我的更新命令不能从DataGridView c#更新数据库
本文关键字:更新 数据库 DataGridView 不能 命令 我的 | 更新日期: 2023-09-27 18:19:10
这是我从datagridview更新数据库的代码,如果有人有答案请告诉我。
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());
}
我对代码进行了一些编辑,现在它对我来说工作得很好。我忘了申报sda。
删除命令= 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());
}