【发布时间】:2014-06-11 21:04:41
【问题描述】:
我在从数据库中删除选定行时遇到问题,事实上,我在 C# 中有一个表单,其中包含一个连接到数据库的 dataGridView 和一个“删除”按钮,当我单击该按钮时,这应该删除信息从 dataGridView 和数据库中的选定行(单元格 [0] 和单元格 [1])。现在,我遇到了从数据库中删除选定行的问题,这是我的代码:
private void button4_Click(object sender, EventArgs e)
{
if (journalDataGridView.SelectedRows.Count == 1)
{
DataGridViewRow row = journalDataGridView.SelectedRows[0];
journalDataGridView.Rows.Remove(row);
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand sql = new SqlCommand("delete from journal where code_journal='" + journalDataGridView.CurrentRow.Cells[0].Value.ToString() + "'AND intitule='" + journalDataGridView.CurrentRow.Cells[1].Value.ToString() + "';", connection);
connection.Close();
}
}
dataGridView 包含两列“code_journal 和 initule” 感谢您的帮助
【问题讨论】:
-
initule 或 intitule ??
-
这是 intitule @Andy G :)
标签: c# sql database datagridview