views:

72

answers:

3

I wanna update my database from my dataset.

mydataadapter = new MySqlDataAdapter("SELECT * FROM table0; SELECT * FROM table1; SELECT * FROM table2;", con);

myda.Fill(dataset);
//......
// for example I'm doing a change like this
ds.Tables[2].Rows[1][3] = "S";

//Then updating the database
MySqlCommandBuilder com = new MySqlCommandBuilder(mydataadapter);
mydataadapter.Update(dataset, "table2");

then it returns this error

TableMapping['table2'] or DataTable 'table2' didn't find by Update.

Do you have any advice?

+2  A: 

The DataAdaptor does not know about table2, only a 3rd recordset (loaded into ds.Tables[2])

You need a table mapping to do this.

Edit: You have an UpdateCommand, right?

gbn
I did it and no errors return. But database dosn't change. May I add executenonquery etc :S
Ases
MySqlCommandBuilder com = new MySqlCommandBuilder(mydataadapter);isn't it do it?
Ases
A: 

try this http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041

anishmarokey
I think it doesn't solve my problem..
Ases
A: 

Not an answer, but if this is for a real production application, then in my opinion, dump the dataset mentality and get a real ORM, so you can work with actual objects and save them properly. Use Entity Framework, Linq-to-SQL, NHibernate, anything but datasets. Once you do that, you'll find it much easier in the long term to retrieve and save data.

In the meantime, I'd go with gbn's answer.

Joe Enos
you are true, I'm searching orm. Thanks...
Ases