我不知道它是什么,但我对这个gridview有各种各样的问题。下面是代码,但问题是网格没有显示。可见性设置为true,查询确实返回结果。所以我要求另一组眼睛指出这里出了什么问题。
谢谢
protected void btnDisplay_Click(object sender, EventArgs e)
{
string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\levels.mdb";
DataSet ds;
using (OleDbConnection myConnString = new OleDbConnection())
{
myConnString.ConnectionString = connString;
using (OleDbCommand selectCommand = new OleDbCommand())
{
selectCommand.CommandText = "select * from tblTest";
selectCommand.Connection = myConnString;
myConnString.Open();
using(OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = selectCommand;
ds = new DataSet();
da.Fill(ds, "test");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
}//end click event
和gridview
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
答案 0 :(得分:0)
数据源应该是:
GridView1.DataSource = ds.Tables["test"];
GridView1.DataBind();
答案 1 :(得分:0)
或
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();