我有這樣一個樣表:驗證登錄與phpMyAdmin
我創建dbconnect
類選法,它是這樣的:
public List<string>[] Select(string username, string password)
{
string query = "SELECT * FROM ms_user where username = '" + username +
"' and password = '" + password + "'";
//Create a list to store the result
List<string>[] list = new List<string>[2];
list[0] = new List<string>();
list[1] = new List<string>();
//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["username"] + "");
list[1].Add(dataReader["password"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return list;
}
else
{
return list;
}
}
如何使用這個方法登錄?由於該方法正在返回一個列表,而不是true
或false
以檢查數據庫中是否存在該值。
沒有明顯的研究努力,投票關閉 – 2013-03-14 08:21:50
你是說你需要返回列表和真或假嗎? (可以使用'out'參數) 你的代碼可以通過在if語句之外移動列表的方式進行改進,那麼你不需要else – Sayse 2013-03-14 08:22:34
,因爲我不知道如何處理返回的列表:( – Cignitor 2013-03-14 08:22:35