<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"></asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="dataadapter"
SelectMethod="getdata"></asp:ObjectDataSource>
public class dataadapter
{
private static readonly string _lianjie;
public DataTable getdata()
{//初始化SqlDataAdapter
SqlDataAdapter d = new SqlDataAdapter("selete 列1 from 练习表", _lianjie);
DataTable dt = new DataTable();//创建一个DataTable对象
d.Fill(dt);//填充表dt
return dt;//返回结果,
}
static dataadapter() {
_lianjie = WebConfigurationManager.ConnectionStrings["练习表"].ConnectionString;
}
}
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="dataadapter"
SelectMethod="getdata"></asp:ObjectDataSource>
public class dataadapter
{
private static readonly string _lianjie;
public DataTable getdata()
{//初始化SqlDataAdapter
SqlDataAdapter d = new SqlDataAdapter("selete 列1 from 练习表", _lianjie);
DataTable dt = new DataTable();//创建一个DataTable对象
d.Fill(dt);//填充表dt
return dt;//返回结果,
}
static dataadapter() {
_lianjie = WebConfigurationManager.ConnectionStrings["练习表"].ConnectionString;
}
}