0
我真的需要你的幫助我在一個學校項目工作。 我使用SqlDataReader來存儲我的數據後,存儲數據(和它的工作,我檢查時,調試sqldatareader結果視圖充滿了我的數據)當我嘗試使用sqldatareader變量,它具有所有的數據,它直接變爲空? ? 在進入if行之前我的sqlreader包含了所有的數據,但是當我調試if行時,它顯示sqlreader是空的!sql數據讀取器變空時,我想使用它
class ServicesProvider
{
public static SqlConnection connection = new SqlConnection(myprovider);
public static bool LogInVerification(string NickName,string Password)
{
SqlDataReader SqlReader;
SqlCommand command;
try
{
command = new SqlCommand("Check_LogIn", connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter prm=null;
prm = new SqlParameter("@Password", SqlDbType.VarChar);
prm.Value=NickName;
prm.Direction=ParameterDirection.Input;
command.Parameters.Add(prm);
prm = new SqlParameter("@NickName", SqlDbType.VarChar);
prm.Value=Password;
prm.Direction=ParameterDirection.Input;
command.Parameters.Add(prm);
try
{
connection.Open();
SqlReader = command.ExecuteReader();
if (SqlReader["NickName"].ToString()== "1")
return true;;
}
catch (Exception ERROR)
{
Console.WriteLine(ERROR.Message);
}
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
return false;
}
}
非常感謝你剛剛救了我(現在有效):) –
@Mostafa Sarsour:選擇上面的'檢查'標記標記爲答案。 – houssam