我使用vs2005的向导连接到数据库,连接时一切正常,并且测试连接时也可以成功的看到要查找的字段,可是为什么在页面预览是看不到数据
程序如下:div id= "mainbody ">
<asp:DataList ID= "DataList1 " runat= "server " DataSourceID= "SqlDataSource1 " RepeatColumns= "4 ">
</asp:DataList> <asp:SqlDataSource ID= "SqlDataSource1 " runat= "server " ConnectionString= " <%$ ConnectionStrings:mydatabaseConnectionString %> "
SelectCommand= "SELECT [name] FROM [ctg2] "> </asp:SqlDataSource>
<asp:Button ID= "Button1 " runat= "server " Text= "Button " OnClick= "Button1_Click " />
</div>
------解决方案--------------------控件和数据绑定呢?
try
{
myconn.Open();
string sql = "select * from ctg2 ";
SqlCommand mycomm= new SqlCommand (sql);
mycomm.ExecuteNonQuery();
myconn.Close();
}
只是执行了一下sql语句 并没有返回任何数据集
------解决方案--------------------是不是没写DataBind();
------解决方案--------------------try
{
myconn.Open();
string sql = "select * from ctg2 ";
datatable dt=new datatable();
sqlDataAdapter adapter=new sqldataadapter(sql,myconn);
adapter.fill(dt);
messagebox.show(dt.rows.count.tostring());
this.gridview.datasource=dt;
myconn.Close();
}
catch (Exception )
{
}
------解决方案--------------------还没有定义显示数据的 模板
<ItemTemplate>
.................
</ItemTemplate>
没这个,你怎么显示数据?显示到哪里?