ASP.NET如何操作数据库?
ASP.NET(C#)如何对数据库(SQL)进行访问修改!是ADO.NET吗?有没有什么代码给我看看最好简单点...
ASP.NET(C#)如何对数据库(SQL)进行访问修改!是ADO.NET吗?有没有什么代码给我看看 最好简单点
展开
1个回答
展开全部
执行一个简单的Select查询,并返回数据表到DataGrid
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=pubs");
SQLDataSetCommand myCommand = new SQLDataSetCommand("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.FillDataSet(ds, "Authors");
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
</script>
<body>
<h3><font face="Verdana">撼雪喷云之查询数据表返回到 DataGrid </font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
headerStyle-BackColor="#aaaadd"
MaintainState="false"
/>
</body></html>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=pubs");
SQLDataSetCommand myCommand = new SQLDataSetCommand("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.FillDataSet(ds, "Authors");
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
</script>
<body>
<h3><font face="Verdana">撼雪喷云之查询数据表返回到 DataGrid </font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
headerStyle-BackColor="#aaaadd"
MaintainState="false"
/>
</body></html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询