Asp中将TextBox控件的内容插入到sql2005的数据库中
stringstr="Server=.;DataBase=Student;userid=sa;password=123";SqlConnectionmyConnectio...
string str = "Server=.;DataBase=Student;user id=sa;password=123";
SqlConnection myConnection = new SqlConnection(str);
myConnection.Open();
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;
string str3 = "Insert into User_Info(Name,Password) values(str1,str2)";
SqlCommand myCommand = new SqlCommand(str3,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
错误提示:在此上下文中不允许使用名称 "str1"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名 展开
SqlConnection myConnection = new SqlConnection(str);
myConnection.Open();
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;
string str3 = "Insert into User_Info(Name,Password) values(str1,str2)";
SqlCommand myCommand = new SqlCommand(str3,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
错误提示:在此上下文中不允许使用名称 "str1"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名 展开
展开全部
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;
SqlParameter[] sp = new SqlParameter[]{
new SqlParameter("@name",str1 ),
new SqlParameter("@password",str2 )
};
string sql = "insert bg_class(name,password) values(@name,@password)";
string str2 = TextBox2.Text;
SqlParameter[] sp = new SqlParameter[]{
new SqlParameter("@name",str1 ),
new SqlParameter("@password",str2 )
};
string sql = "insert bg_class(name,password) values(@name,@password)";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询