Sorry for the probably stupid question. Since I found nothing about it on the internets, its probably totally obvious and I’m just to blind to see?!
I’m trying to update a table in a database from a dataset via DataAdapter.Update(dataset)
But there is no possiblity to set the connection, the DA should use.
Where does the DA know how to connect to the DB? Or do I misunderstand the concept of the dataadapter?
my current code is like:
protected DataSet UpdateDataSet(DataSet ds)
{
DataSet dsChanges = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
dsChanges = ds.GetChanges();
//Update DataSet
da.Update(dsChanges);
ds.Merge(dsChanges);
return ds;
}
I just wrote this and became suspicious how (or if) it works… I havent tested it so far, since I gotta write some other code before I can test it properly
Thank you ppl, StackOVerflow FTW!
A SqlDataAdapter needs to take in a SqlCommand object, which has a SqlConnection object tied to it. That’s pretty much how the hierarchy breaks down.
As for how you go about doing that, there are options for passing them into the constructor, as well as setting the various properties after construction.
Here’s an msdn article with examples of selecting, inserting, updating, and deleting.
FTA: