国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

在ASP.NET中連接SQL Server的簡單方法

2024-07-10 13:16:18
字體:
供稿:網(wǎng)友
首先導(dǎo)入名字空間:System.Data和System.Data.SqlClient.詳細(xì)代碼看源程序.

復(fù)制代碼 代碼如下:


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E )
{
SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=;database=pubs");
//創(chuàng)建對象SqlConnection
string strSQL="SELECT au_id,au_lname,au_fname,phone,address,city,zip FROM authors";
SqlDataAdapter myCmd = new SqlDataAdapter(strSQL, myConn);
//創(chuàng)建對象SqlDataAdapter
DataSet ds = new DataSet();
//創(chuàng)建對象DataSet
myCmd.Fill(ds);
//填充數(shù)據(jù)到Dataset
DataView source = new DataView(ds.Tables[0]);
MyDataGrid.DataSource = source ;
MyDataGrid.DataBind();
//將數(shù)據(jù)綁定到DataGrid
}
</script>
<body>
<h3><font face="Verdana">Simple SELECT to a DataGrid Control
</font></h3>
<ASP:DataGrid runat="server"
Width="600"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沂南县| 台北县| 常州市| 南安市| 德清县| 南开区| 密山市| 淄博市| 双流县| 涞源县| 长海县| 绥芬河市| 大邑县| 昂仁县| 红原县| 镇康县| 腾冲县| 临沭县| 昆明市| 尚志市| 肇州县| 淮滨县| 平罗县| 峡江县| 宝兴县| 西乌| 三河市| 武清区| 宜州市| 阳山县| 公主岭市| 西华县| 丰县| 谷城县| 安康市| 龙泉市| 洪湖市| 镇康县| 西平县| 岳阳县| 泰顺县|