C#用sqlcommand删除数据库中的某一行始终出错。
stringstr=dataGridView1.SelectedCells[0].Value.ToString();stringsql="delete*fromIDwhe...
string str = dataGridView1.SelectedCells[0].Value.ToString();
string sql = "delete * from ID where Ls='"+str+"'";
string consqlserver = "Data Source=.;Initial Catalog=student;Integrated Security=True;";
SqlConnection con = new SqlConnection(consqlserver);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
报错为cmd.ExcecuteNonQuery()附近有语法错误!
数据库中的Id是int,我也尝试过把Str转化成int。但还是报这个错误。 展开
string sql = "delete * from ID where Ls='"+str+"'";
string consqlserver = "Data Source=.;Initial Catalog=student;Integrated Security=True;";
SqlConnection con = new SqlConnection(consqlserver);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
报错为cmd.ExcecuteNonQuery()附近有语法错误!
数据库中的Id是int,我也尝试过把Str转化成int。但还是报这个错误。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询