同时还要写语句删除数据库~
如:
SqlCommand cmd = new SqlCommand()
cmd.Connection = new SqlConnection(sql_connect)
cmd.CommandText = "delete from gl_card_no where card_no = '" + textBox3.Text.Trim() + "'"
if (MessageBox.Show("你确定删除该行么?" + cmd.CommandText + "", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
try
{
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
MessageBox.Show("删除成功!")
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString())
}
finally
{
cmd.Dispose()
}
}
先把一个DataTable和数据库的表绑定,然后DataGridView.DataSource = DataTable
删除时
((DataTable)DataGridView.DataSource).Rows[行号].Delete()
更新时把((DataTable)DataGridView.DataSource)作为DataTable去更新数据库就行。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)