我有以下代码从数据库中选择记录:
public List<string>[] Select(string Command)
{
string query = Command;
//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["NIK"] + "");
list[1].Add(dataReader["Password"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return list;
}
else
{
return list;
}
}
我的表中有 2 列,即NIK
和Password
表有 2 行,即1
,1
和2
, 1
。
如何验证列表是否包含NIK
= 2 和Password
= 1?如何知道select语句是否成功从我的表中获取记录?如何将多列表打印到文本框中?