在我的UI方面,我有一个像这样的网格视图:
Default.aspx的:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
然后我这样做我的代码运行但页面上没有任何内容:
Default.aspx.cs:
OleDbConnection connection = new OleDbConnection(); //Creating a db object
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\mydb.mdb";
try{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query ="Select * From events";
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
}
catch(Exception ex)
{
//error
}
Msaccess数据库:
|ID |Date |Name |Location |age |desc | <--table header
|01 |2 dec|TestName| TestLocation |testAge|testDesc| <--table data
我希望输出看起来像这样:
|Date |Name |Location |age |desc |
|2 dec|TestName| TestLocation |testAge|testDesc|