我正在尝试创建一个返回列的所有数据的方法,以便可以在listview上使用数据来填充它。
public static Array populatelistview()
{
OleDbConnection myConnection = GetConnection();
string query = "SELECT * FROM trainlines_";
OleDbCommand command = new OleDbCommand(query, myConnection);
command.Connection = myConnection;
DataSet trainlinedata = new DataSet();
trainlinedata.Clear();
OleDbDataAdapter datareader = new OleDbDataAdapter(command);
datareader.Fill(trainlinedata);
myConnection.Close();
return trainlinedata;
}
答案 0 :(得分:0)
从问题来看,您似乎可以从相关来源获取数据。我认为你需要的是将这个结果数组绑定到Listview控件。像下面的东西
ListView1.DataSource = trainlinedata.Tables["yourTableName"];
ListView1.DataBind();
答案 1 :(得分:0)
您应该返回DataSet
输入Array
。因为trainlinedata
声明为DataSet
public static DataSet populatelistview()
{
OleDbConnection myConnection = GetConnection();
string query = "SELECT * FROM trainlines_";
OleDbCommand command = new OleDbCommand(query, myConnection);
command.Connection = myConnection;
DataSet trainlinedata = new DataSet();
OleDbDataAdapter datareader = new OleDbDataAdapter(command);
datareader.Fill(trainlinedata);
myConnection.Close();
return trainlinedata;
}