C#,cmd.ExecuteNonQuery();出错了
protectedvoidButton1_Click(objectsender,EventArgse){SqlConnectionconn=newSqlConnectio...
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=shen;database=沈军辉;user id=sa;password=");
int xh = int.Parse(TextBox1.Text);
int nl = int.Parse(TextBox5.Text);
string sql = "insert into 学生(学号,姓名,班级,专业,年龄,性别) values(" + xh + ",'" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "'," + nl + ",'" + TextBox6.Text + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
提交 的时候 cmd.ExecuteNonQuery();这句出错了:',' 附近有语法错误 展开
{
SqlConnection conn = new SqlConnection("server=shen;database=沈军辉;user id=sa;password=");
int xh = int.Parse(TextBox1.Text);
int nl = int.Parse(TextBox5.Text);
string sql = "insert into 学生(学号,姓名,班级,专业,年龄,性别) values(" + xh + ",'" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "'," + nl + ",'" + TextBox6.Text + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
提交 的时候 cmd.ExecuteNonQuery();这句出错了:',' 附近有语法错误 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询