dataset update

M

Mojtaba Faridzad

Hi,

Please check these lines:

DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "mytable");
DataRow row;
row = dataSet.Tables[0].Rows[0];
row.BeginEdit();
row[0] = "555";
row.EndEdit();
//dataSet.AcceptChanges();
dataAdapter.Update(dataSet, "mytable");

I got this error message on dataAdapter.Update line:

Additional information: Update requires a valid UpdateCommand when passed
DataRow collection with modified rows.

with dataSet.AcceptChanges() I don't get error message but the database is
not really changed. when I use datagrid and use dataAdapter.Update() it
works. what's the problem?

my other question, what's the easiest way to edit a value of a field in a
table?

thanks
 
L

Lord2702

Tue. Aug. 31, 2004 11:50 AM PT

See the MSDN documentation, for the SqlDataAdapter, You need to pass four
commands SqlCommand object, which also has the connecton object which
connects to your database, SELECT, INSERT, UPDATE, DELETE. to your data
adapter object, inorder to update PHYSICALLY into your database, otherwise,
with dataset AcceptChanges, changes will be made only in the DataSet, when
you quit the application these changes be loss. Read the MSDN documentation
about updation dataset, and the data adapter.

Good Luck !
 
Z

Zürcher See

DataRow has a flag of his state: DataRow.RowState
The DataAdapter use this flag to know if it need to do nothing a delete an
insert or an update.
If you call the DataRow.AcceptChanges() you reset this flag and the
DataAdapter does nothing.

But your problem is something else, your DataAdpater don't have an
UpdataCommand!!
DataAdapter.UpdateCommand=new SqlCommand("UPDATE ..... ",...);
 

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