我的 datagridview 中有一个组合框列,其中我添加了三个项目插入、更新和删除现在我想选择一个项目并执行相应的操作。
但是当我执行此错误时,显示输入字符串的格式不正确,可能是我无法选择相对于该组合框行的确切行。有人帮忙吗?
这是我的 datagridview 的组合框 SelectedIndexChanged 事件的代码
ComboBox cmb = (ComboBox)sender;
if (cmb.SelectedItem.ToString() == "insert")
{
con = new SqlConnection(@"Data Source=krishna-PC\SQLEXPRESS;Initial Catalog=dbnew;Integrated Security=True");
int a = int.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].ToString());
string b = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
string c = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString();
com = new SqlCommand("insert into mytable values(@a,@b,@c,@d)", con);
com.Parameters.AddWithValue("@a", a);
com.Parameters.AddWithValue("@b", b);
com.Parameters.AddWithValue("@c", c);
com.Parameters.AddWithValue("@d", "govind");
con.Open();
com.ExecuteNonQuery();
MessageBox.Show("Data has been inserted");
}