Here is my code to update the database from datagridview if any body have the answer please tell me.
try
{
if (string.IsNullOrEmpty(tbName.Text) || string.IsNullOrEmpty(cmbSex.Text) || string.IsNullOrEmpty(cmbFeesAmount.Text) || string.IsNullOrEmpty(cmbFeesStatus.Text) || string.IsNullOrEmpty(cmbSex.Text) || string.IsNullOrEmpty(Date.Text)) { MessageBox.Show("Please Input data."); return; }
Update(lblDI.Text);
Reset();
this.BindGrid();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I Done some edits to the code and now it's working fine for me . i forgot to declare the sda.DeleteCommand = cb.GetDeleteCommand();
private static void CurdOperation()
{
SqlCeConnection con = new SqlCeConnection("Data Source="
+ System.IO.Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "MyDB.sdf"));
sda = new SqlCeDataAdapter();
SqlCeCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from tblFees";
sda.SelectCommand = cmd;
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(sda);
sda.InsertCommand = cb.GetInsertCommand();
sda.UpdateCommand = cb.GetUpdateCommand();
sda.DeleteCommand = cb.GetDeleteCommand();
}
#endregion
try
{
if (string.IsNullOrEmpty(tbName.Text) || string.IsNullOrEmpty(cmbSex.Text) || string.IsNullOrEmpty(cmbFeesAmount.Text) || string.IsNullOrEmpty(cmbFeesStatus.Text) || string.IsNullOrEmpty(cmbSex.Text) || string.IsNullOrEmpty(Date.Text)) { MessageBox.Show("Please Input data."); return; }
Update(lblDI.Text);
Reset();
this.BindGrid();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Now it Works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.