我收到此錯誤「執行閱讀器需要打開連接」。我用Google搜索了一切,並嘗試了一切。我似乎找不到錯誤的根源。它昨天在工作。執行閱讀器需要打開連接
public bool ValidRegLogUser()
{
bool _UserValid = false;
try
{
string querystring = "Select * from users where [email protected] and [email protected]";
SqlCommand command = new SqlCommand(querystring,con);
command.Parameters.Add("@userName", SqlDbType.VarChar).Value = UserName;
command.Parameters.Add("@userPassword", SqlDbType.VarChar).Value = Password;
openConnection();
using (SqlDataReader conReader = command.ExecuteReader())
{
if (conReader.Read() == true)
{
UserName = Convert.ToString(conReader["userName"]);
LogType = Convert.ToString(conReader["userPrivileges"]);
_UserValid = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//conReader.Close();
closeConnection();
}
return _UserValid;
什麼是'openConnection();'?有什麼方法可以做到這一點? – prospector
嘗試把conReader.open()。 – varsha
@varsha他甚至沒有連接打開在這一點上,所以這是行不通的。 – prospector