0
因此,我爲我的公司創建了一個小型應用程序,讓用戶登錄並訪問特定數據,但是,在服務器端查詢數據庫,MySqlDataReader不讀取,正如我在下面的代碼:MySqlDataReader does not read
public string HandleLogin(string uname, string pwd)
{
MySqlDataReader READER;
int count = 0;
int clearance = 0;
if (uname == "" || pwd == "")
return "";
CONN = new MySqlConnection();
CONN.ConnectionString = Config.CONNSTRING;
string query = "select * from members where username='" + uname + "' and password='" + pwd + "'";
try
{
CONN.Open();
COMMAND = new MySqlCommand(query, CONN);
READER = COMMAND.ExecuteReader();
while(READER.Read())
{
count = count + 1; //<-- this should happen, but it doesnt
if (count == 1)
clearance = READER.GetInt32("clearance");
else
return "";
}
if (count == 1)
return Convert.ToString(clearance);
else
return "";
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return "";
}
finally
{
CONN.Dispose();
}
}
我相信它應該讀1行,要求它發現行的量,它說0,但我三重檢查所有的價值觀和嚴絲合縫的數據庫值,但它讀取無查詢的行。這可能是一個非常愚蠢的錯誤,但我無法找到問題。
打印並驗證sql文本是否正確。在uname/pwd變量中查找任何空格。 – RajN
您是否檢查過連接是否打開? – Clock
@RajNagalingam這是正確的,@ devlincarnate有,但密碼在數據庫中被散列,並在服務器收到它和@ SomeUser嗯謝謝,我一定會考慮它 –