各位大侠,请看下面代码
string strTxt;
SqlConnection conn = new SqlConnection("Data Source=localhost;DataBase=researchdb;user=sa;password=gh001");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from sorttable",conn);
strTxt=SortNameTB.Text ;
string mySelectQuery="insert into sorttable values('004',strTxt)";
SqlCommand myCommand = new SqlCommand(mySelectQuery,conn);
myCommand.ExecuteNonQuery();
conn.Close ();
奇怪,出错!!!!!!!真不解why!
高分相送.
急!!!!!在线盼!!!!!!!!!!!!!
string strTxt;
SqlConnection conn = new SqlConnection("Data Source=localhost;DataBase=researchdb;user=sa;password=gh001");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from sorttable",conn);
strTxt=SortNameTB.Text ;
string mySelectQuery="insert into sorttable values('004',strTxt)";
SqlCommand myCommand = new SqlCommand(mySelectQuery,conn);
myCommand.ExecuteNonQuery();
conn.Close ();
奇怪,出错!!!!!!!真不解why!
高分相送.
急!!!!!在线盼!!!!!!!!!!!!!
改称
string mySelectQuery="insert into sorttable values('004'," + strTxt + ")";
改称
string mySelectQuery="insert into sorttable values('004','" + strTxt + "')";
strTxt是你定义的变量,
改成:
string mySelectQuery="insert into sorttable values('004','" + strTxt + "')";
改为
string mySelectQuery="insert into sorttable values('004',"+strTxt+")";
我在文本框中输入"这次一定行",结果出现如下错误:
在此上下文中不允许使用 '这次一定行'。此处只允许使用常量、表达式或变量。不允许使用列名。
string mySelectQuery="insert into sorttable values('004','" + strTxt + "')";
这个行
比如:
string val = "hhhhhh";
"SET field1 = '"+
val+
"'";