我正在尝试将一些数据加载到 DataGridView 中,但是 DataGridView 没有显示数据(即使它在调试模式下说它有项目)
protected void PopulateGrid()
{
string dataSource = "test.db";
String connectionString = "Data Source=" + dataSource;
String selectCommand = "SELECT * FROM test_run";
SQLiteDataAdapter dataAdapter =
new SQLiteDataAdapter(selectCommand, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.Refresh();
}
或者它不起作用并出现错误:“datareader has been active on this command”
protected void PopulateGrid()
{
SQLiteConnection SQLconnect = new SQLiteConnection();
SQLiteCommand SQLcommand = default(SQLiteCommand);
SQLiteDataAdapter SQLAdapt = new SQLiteDataAdapter();
SQLiteDataReader SQLreader = default(SQLiteDataReader);
DataTable db = new DataTable();
SQLconnect.ConnectionString = "Data Source=test.db;MultipleActiveResultSets=True";
SQLconnect.Open();
SQLcommand = SQLconnect.CreateCommand();
SQLcommand.CommandText = "SELECT * FROM test_run;";
SQLreader = SQLcommand.ExecuteReader();
SQLAdapt.SelectCommand = SQLcommand;
SQLAdapt.Fill(db);
dataGridView1.DataSource = db.DataSet;
dataGridView1.Refresh();