0
这是我的登录代码。我正在处理我的dbms项目。我已经删除了所有的错误,因为错误列表显示0错误,但是当我执行此操作时,我在我的网页顶部发生此错误关键字'用户'附近的语法不正确。和剩余的页面上有我的登录窗体出现。我不知道如何解决这一切。请尽快通知我。 这里是登录页面的代码。 保护无效的button1_Click(对象发件人,EventArgs的) { 尝试 { //用于链接数据库如何解决此语法错误?
SqlConnection conn = new SqlConnection("Data Source=BUSHRA-PC\\SQLEXPRESS;Initial Catalog=fb;Integrated Security=True");
conn.Open(); // openning connection
SqlCommand cmd = new SqlCommand("select * from user where Userid='" + TextBox1.Text + "'", conn);
//cmd.Connection = conn;
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr["Userid"].ToString();
}
cmd.Connection = conn;
while (dr.Read())
{
Application["Userid"] = dr[0].ToString();
Application["Password"] = dr[1].ToString();
Application["Rollid"] = dr[2].ToString();
if (dr[0].ToString() == TextBox1.Text && dr[1].ToString() == TextBox3.Text)
{
if (Convert.ToInt16(dr[2].ToString()) == 2)
{
Response.Redirect("Admin.aspx");
}
else if (Convert.ToInt16((dr[2])) == 1)
{
Response.Redirect("StudentFB.aspx");
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message); // if try fails display the error
}
这可能是一个[tag:syntax-error],但是它是什么* language *,可以考虑将其添加到您的标签中。 –
TextBox1.Text的价值是什么?是否有任何单引号? – Marc
在你的SQL中使用TextBox1.Text的手腕上打耳光。您很容易受到SQL注入攻击。你应该解决这个问题。 http://en.wikipedia.org/wiki/SQL_injection – webnoob