このC#関数はリストを返します。関数は.dllファイルにあります。 ASPXページにリストを戻す方法。私はASP.Netを初めて使っていて、それをグリッドにバインドしようとしましたが、動作しません。ASPXページのリストを表示
public static List<string>[] Select()
{
server = "localhost";
database = "cdl";
uid = "root";
password = "password";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
connection.Open();
string query = "SELECT * FROM caleiddevice";
//Create a list to store the result
List<string>[] list = new List<string>[3];
list[0] = new List<string>();
list[1] = new List<string>();
list[2] = 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();
// MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(query, connection);
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["device_id"] + "");
list[1].Add(dataReader["status"] + "");
list[2].Add(dataReader["timestamp"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
// this.CloseConnection();
//return list to be displayed
return list;
//}
//else
//{
// return list;
// }
}
あなたはaspx.cs であなたのGridViewをバインドするために使用され、任意の – Devjosh
は個人的に私は「wouldn場合は、どのようなエラーを取得しているあなたのコードを投稿し正常に動作しますリストの配列を使用しますが、 'List' 'DeviceInfo 'は3つのプロパティ(DeviceId、Status、Timestamp)を持つ新しいクラスです。 –