我遇到了错误,我也不知道代码有什么问题,所以如果有人可以帮助我,我将不胜感激。

错误:



突出显示的行是

rdr = cmd.ExecuteReader();

码:
cn.Open();
string query = "SELECT * FROM dbo.ispiti WHERE poID=@poID, sgID=@sgID, npID=@npID";

SqlCommand cmd = new SqlCommand(query, cn);

cmd.Parameters.AddWithValue("@poID", pr);
cmd.Parameters.AddWithValue("@sgID", pr1);
cmd.Parameters.AddWithValue("@npID", pr2);

SqlDataReader rdr;

try
{
    rdr = cmd.ExecuteReader();

    if (rdr.Read())
    {
        MessageBox.Show("Well done!");
    }
}
catch(exception ex)
{
    MessageBox.Show("Error!");
}
finally
{
    cn.Close();
}

最佳答案

您的SQL语句中有错误。你应该改变

string query = "SELECT * FROM dbo.ispiti WHERE poID=@poID, sgID=@sgID, npID=@npID";


string query = "SELECT * FROM dbo.ispiti WHERE poID=@poID AND sgID=@sgID AND npID=@npID";

10-05 22:31