I have an application I have been working on and up until now I have been using Access as a Database. I am switching it over to SQL and I am kinda new to it.
My code is as follows
public bool Update_DB_FromTable(DataTable DTable)
{
try
{
SqlConnection myConnection = new SqlConnection("Data Source=" + hostname + " ;User ID=SALX; Password=password;" +
"database=" + dbname + "; " +
"connection timeout=30");
myConnection.Open();
SqlCommand myCommand = new SqlCommand("SELECT * FROM dbo." + tablename, myConnection);
SqlDataAdapter da = new SqlDataAdapter(myCommand);
SqlCommandBuilder b = new SqlCommandBuilder(da);
int count = da.Update(DTable);
myConnection.Close();
return true;
}
catch
{
return false;
}
}
This works, BUT every time it runs its just appends the data to the end of the database and doesn’t “Update” the database like in Access. worst part is because it creates many duplicate entries I cant manually delete them from the database..
Any help would be greatly appreciated.
Cheers,
-Sean-
This might be a really rookie question but i am stumped..
The rows in “DTable” decide what happens with the corresponding row in the database. if a row in “DTable” has status “isNew” then the row will be inserted, if the status is “modified” the db-table will be updated.