asp.net 中SQL语句问题,
stringsel="SELECTUser_Name,User_PasswordFROMUserWHEREUser_Name=tname.textANDUser_Pass...
string sel = "SELECT User_Name,User_Password FROM User WHERE User_Name=tname.text AND User_Password=tpassword.Text";
SqlConnection con = linkdatabase.CreateConnection();
con.Open();
SqlCommand command = new SqlCommand();
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = sel;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
总是提示Incorrect syntax near the keyword 'User'.
SELECT User_Name, User_Password FROM [User] WHERE (User_Name = '"+tname.Text+"') AND (User_Password = '"+tpassword.Text+"')";
我自己解决了应该是这样 展开
SqlConnection con = linkdatabase.CreateConnection();
con.Open();
SqlCommand command = new SqlCommand();
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = sel;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
总是提示Incorrect syntax near the keyword 'User'.
SELECT User_Name, User_Password FROM [User] WHERE (User_Name = '"+tname.Text+"') AND (User_Password = '"+tpassword.Text+"')";
我自己解决了应该是这样 展开
3个回答
展开全部
语法不对啊。
User_Name=tname.text AND User_Password=tpassword.Text
这些应该用字符串拼接的。不能直接写到一起。
User_Name=tname.text AND User_Password=tpassword.Text
这些应该用字符串拼接的。不能直接写到一起。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
晕,string sel = "SELECT User_Name,User_Password FROM User WHERE User_Name=tname.text AND User_Password=tpassword.Text";
改下:string sel = "SELECT User_Name,User_Password FROM User WHERE User_Name=‘ “ +tname.text +“ ’ AND User_Password= ' ”+tpassword.Text+“ ’ ";
改下:string sel = "SELECT User_Name,User_Password FROM User WHERE User_Name=‘ “ +tname.text +“ ’ AND User_Password= ' ”+tpassword.Text+“ ’ ";
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-18
展开全部
LZ 你让我找到了自尊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询