本文介绍了如何解决必须在SQL insert命令上声明标量变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! protected void Add_Click( object sender,EventArgs e) { string constr = ConfigurationManager.ConnectionStrings [ ApplicationServices]。ConnectionString; SqlConnection con = new SqlConnection(constr); // SqlCommand cmd = new SqlCommand(插入学生值('+ RegNo.Text + ','+ Name.Text +','+ Address.Text +')); SqlCommand cmd = new SqlCommand( 插入学生(@ RegNo,@ Name,@ Address,@ CreatedTime)值(@ RegNo,@名称,@地址,GETDATE())); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } 我的尝试: 这里尝试插入记录。我有3个文本框,即RegNo,Name,Address,在我的表中,我有$列RegNo,Name,Address,CreatedTime。在我的代码中遇到以下错误。 必须声明标量变量@RegNo 。 做什么。解决方案 protected void Add_Click(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; SqlConnection con = new SqlConnection(constr); //SqlCommand cmd = new SqlCommand("insert into Student values('" + RegNo.Text + "','" + Name.Text + "','" + Address.Text + "')"); SqlCommand cmd = new SqlCommand("insert into Student(@RegNo,@Name,@Address,@CreatedTime) values(@RegNo,@Name,@Address,Getdate())"); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); }What I have tried:here am try to insert records . i have 3 textboxes namely RegNo,Name,Address and in my table I have $ columns RegNo,Name,Address,CreatedTime. in my code the following error encountered .Must declare the scalar variable @RegNo . what to do. 解决方案 这篇关于如何解决必须在SQL insert命令上声明标量变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 18:25