private void gridselect(object sender, DataGridViewCellEventArgs e)
{
chooseAnyRow = e.RowIndex;
DataGridViewRow row = bndisplay.Rows[chooseAnyRow];
textBox1.Text = row.Cells[5].Value.ToString();
}
private void button7_Click(object sender, EventArgs e)
{
DataGridViewRow deleterow = bndisplay.Rows[chooseAnyRow];
deleterow.Cells[5].Value = textBox1.Text;
/*com = con.CreateCommand();
com.CommandType = CommandType.Text;
com.CommandText = "delete from candidateRegistration where icnumber = '' " + textBox1.Text;
*/
SqlConnection con;
SqlCommand com;
string connstring = @"Data Source=dasranrajlui\sqlexpress;Initial Catalog=SESoriginal;Integrated Security=True";
con = new SqlConnection(connstring);
con.Open();
string sqlstr = "delete from candidateRegistration where icnumber= " + textBox1.Text;
sqlstr = sqlstr + "" + textBox1.Text + ")";
com = new SqlCommand(sqlstr, con);
try
{
com.ExecuteNonQuery();
MessageBox.Show("deleted...");
textBox1.Text = null;
}
catch (Exception EX)
{
MessageBox.Show(EX + "NOT deleted");
}
finally
{
con.Close();
}
}
好的我已经编辑了代码,但现在我收到了这个错误:
System.Data.SqlClient.SqlException(0x801319404):语法不正确 靠近')' .....
答案 0 :(得分:0)
您没有声明名为“com”的对象
将com.ExecuteNonQuery();
更改为comm.ExecuteNonQuery();
答案 1 :(得分:0)