Search code examples
c#windows-mobile-6sql-server-ce-3.5

sqlCeDataAdapter.update, Update requires a valid UpdateCommand when passed DataRow collection with modified rows


**strong text* hi all this is my code :

for(int i =0 ;i<listView1.Items.Count;i++)
        {
            if(listView1.Items[i].Checked)
            {
                DataRow dr = ds.Tables["EXPORT"].Rows[i];
                dr.BeginEdit();
                dr["MODE_PAIEMENT"] = "cheque";
                dr["SOLDE_RESTANT"] = "0";
                dr.EndEdit();
                //dt.AcceptChanges();
                //ds.Merge(dt);
                try
                {
                    connexion.da.Update(ds, "EXPORT");
                }
                catch (Exception x) {
                    MessageBox.Show(x.ToString());
                }

i have that erreur : Update requires a valid UpdateCommand when passed DataRow collection with modified rows. What shoud i do !! !


Solution

  • You need to do what it says, and set the UpdateCommand Property of the DataAdapter with your SQL UPDATE statement.

    SqlDataAdaptor.UpdateCommand property

    SqlCommand updateCmd = new SqlCommand();
    updateCmd.CommandText = "UPDATE table SET col=@val";
    
     connexion.da.UpdateCommand = updateCmd;