[英]delete from selected datagridview
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):')' 附近的語法不正確.....
您沒有名為“com”的對象聲明更改com.ExecuteNonQuery();
到comm.ExecuteNonQuery();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.