Newbie question on data binding

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
 
L

larrywoods

Actually, I'm trying to do an insert, not an update, but your point is
well-taken -- there has to be an SQL INSERT statement for the
TableAdapter or it will throw an exception. But there is one already,
generated by the wizard when the TableAdapter and typed dataset were
created, and the INSERT statement is just what you would expect it
would be.

So that is not the problem. Any other thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top