protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
{
string username = this.TextBox1.Text;
string password = this.TextBox2.Text;
string str="select * from user where username ='" + username + "'";
SqlConnection conn = new SqlConnection("Data Source=localhost;initial Catalog=sjlerp;uid=sa;pwd=****");
SqlCommand com = new SqlCommand(str,conn);
conn.Open();
SqlDataReader rea = com.ExecuteReader();
}
}
}运行的红色的位置的时候总提示'user'附近有语法错误
{
if (Page.IsValid)
{
{
string username = this.TextBox1.Text;
string password = this.TextBox2.Text;
string str="select * from user where username ='" + username + "'";
SqlConnection conn = new SqlConnection("Data Source=localhost;initial Catalog=sjlerp;uid=sa;pwd=****");
SqlCommand com = new SqlCommand(str,conn);
conn.Open();
SqlDataReader rea = com.ExecuteReader();
}
}
}运行的红色的位置的时候总提示'user'附近有语法错误
这里引号很奇怪
user是保留字
在外面加个分号[user]就行了
....select * from [user] where....
我前几天才遇到的问题,也是这么解决的
user 是保留字,可以写成[user]或改名字users