내 응용 프로그램의 DataGridview가 있습니다. SqlCommand
을 사용하여 datagridview 열 값을 업데이트하려고하는데 코드가 있지만 오류가 표시됩니다. 내가 어떻게 할 수 있니?C#의 SqlCommand를 사용하여 datagridview 셀 값을 업데이트하십시오.
private void EDIT(object sender, EventArgs e)
{
foreach (DataGridViewRow row in datagrid.Rows)
{
if (datagrid.Rows.Count > 0)
{
int nRowIndex = datagrid.Rows.Count - 2;
if (datagrid.Rows[nRowIndex].Cells[0].Value != null)
{
con.Open();
SqlCommand cmd11 = new SqlCommand("update Purchasedetail set [email protected] ,[email protected],[email protected],[email protected],[email protected] where [email protected]_id, [email protected]_name", con);
cmd11.Parameters.AddWithValue("@product_id", row.Cells[0].Value);
cmd11.Parameters.AddWithValue("@product_name", row.Cells[1].Value);
cmd11.Parameters.AddWithValue("@qty", row.Cells[2].Value);
cmd11.Parameters.AddWithValue("@price", row.Cells[3].Value);
cmd11.Parameters.AddWithValue("@tax", row.Cells[4].Value);
cmd11.Parameters.AddWithValue("@discount", row.Cells[5].Value);
cmd11.Parameters.AddWithValue("@total", row.Cells[6].Value);
cmd11.ExecuteNonQuery();
MessageBox.Show("Updated Successfully", "OUTPUT", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
con.Close();
}
정확히 어느 줄에 오류가 무엇입니까? 'SqlConnection'이'Open'입니까? –
이미 추가했습니다 – user3467599