Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在预期条件的上下文中指定的非布尔类型的表达式,靠近“ID”_C#_Asp.net_Visual Studio - Fatal编程技术网

C# 在预期条件的上下文中指定的非布尔类型的表达式,靠近“ID”

C# 在预期条件的上下文中指定的非布尔类型的表达式,靠近“ID”,c#,asp.net,visual-studio,C#,Asp.net,Visual Studio,有人能指出是什么导致了这个错误吗?我一直想把它修好,但失败了。我不明白“ID”有什么问题。。。到底是哪个部分产生了这个错误 这是我的密码: protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = SqlDataSource1.ConnectionString; string st

有人能指出是什么导致了这个错误吗?我一直想把它修好,但失败了。我不明白“ID”有什么问题。。。到底是哪个部分产生了这个错误

这是我的密码:

protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = SqlDataSource1.ConnectionString;

    string str = "SELECT * FROM Student "
        + " WHERE Student ID = '" + StudentID.Text + "' AND "
        + " Password = '" + SPassword.Text + "'";

    SqlCommand cmdSelect = new SqlCommand(str, conn);
    SqlDataReader reader;

    conn.Open();
    reader = cmdSelect.ExecuteReader();


    if (reader.Read())
    {

        if (StudentID.Text == "900000000")

            Response.Write("<body onload=\"window.open('Admin.aspx', '_top')\"></body>");

        else

            Response.Write("<body onload=\"window.open('user.aspx', '_top')\"></body>");

    }
    else
        lblMsg.Text = "Invalid Username and/or Password, please re-try!!";

    conn.Close();

}
从Student.ID所在的学生中选择*。。。你有一个空格而不是一个点


您可以完全忽略该学生,只需使用ID作为密码。

在我修复它之后。。出现一个新错误,显示无效的列名“StudentID”。原因可能是什么?尽管更正,但这不是一个好建议-OP需要使用参数化查询来构造SQL请求。您试图从DB中提取的ID列的名称是什么?-这就是您在SELECT语句中需要的内容。@John3136它的名称是'StudentID。。在SELECT语句中也是如此。@AlexeiLevenkov我不知道,这就是我在大学里学习它的方式。请你提供一个资源,教你的建议?谢谢。使用SQL注入显式编写代码不是一个好主意。请检查使用参数化查询的正确方法。