L
larrywoods
I'd appreciate it if someone can tell me the probably very simple
answer to this question. I have some typed datasets and table adapters
added using VS.2005 in C#. If I want to programatically insert a row
in a database table, I know I can do the following, but think it is
probably not the best way:
FooDataSetTableAdapters.FOOTableAdapter ta = new
FooDataSetTableAdapters.FOOTableAdapter();
ta.Connection.ConnectionString = "my connection string";
ta.Insert("name", "address");
This works, but what I'd rather be able to do is to create the table
adapter, set its connecton string, create a typed dataset instance,
fill its data table with the table adapter, make changes to the table
in the typed dataset, and then use ta.Update(dataset.table) to put the
changes in the database. The problem is that it doesn't work. I can
certainly fill the dataset's table and make changes to it, but the
Update() call doesn't save any of those changes (or give an error).
I'm suspecting that perhaps this is because I didn't do anything
explicit to set the dataset/datatable binding (perhaps since it is a
typed dataset, the binding is set by default? beats me).
What do I need to add to the following to make it work? Thanks
FooDataSetTableAdapters.FOOTableAdapter ta = new
FooDataSetTableAdapters.FOOTableAdapter();
ta.Connection.ConnectionString = "my connection string";
FooDataSet ds = new FooDataSet();
ta.Fill(ds.FOO);
ds.FOO.Rows[0]["mycolumnname"] = "somechange";
ds.AcceptChanges(); // Is this necessary?
ta.Update(ds.FOO); // returns 0 and does nothing
answer to this question. I have some typed datasets and table adapters
added using VS.2005 in C#. If I want to programatically insert a row
in a database table, I know I can do the following, but think it is
probably not the best way:
FooDataSetTableAdapters.FOOTableAdapter ta = new
FooDataSetTableAdapters.FOOTableAdapter();
ta.Connection.ConnectionString = "my connection string";
ta.Insert("name", "address");
This works, but what I'd rather be able to do is to create the table
adapter, set its connecton string, create a typed dataset instance,
fill its data table with the table adapter, make changes to the table
in the typed dataset, and then use ta.Update(dataset.table) to put the
changes in the database. The problem is that it doesn't work. I can
certainly fill the dataset's table and make changes to it, but the
Update() call doesn't save any of those changes (or give an error).
I'm suspecting that perhaps this is because I didn't do anything
explicit to set the dataset/datatable binding (perhaps since it is a
typed dataset, the binding is set by default? beats me).
What do I need to add to the following to make it work? Thanks
FooDataSetTableAdapters.FOOTableAdapter ta = new
FooDataSetTableAdapters.FOOTableAdapter();
ta.Connection.ConnectionString = "my connection string";
FooDataSet ds = new FooDataSet();
ta.Fill(ds.FOO);
ds.FOO.Rows[0]["mycolumnname"] = "somechange";
ds.AcceptChanges(); // Is this necessary?
ta.Update(ds.FOO); // returns 0 and does nothing