• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    在ASP.NET中连接SQL Server的简单方法
    首先导入名字空间:System.Data和System.Data.SqlClient.详细代码看源程序.
    复制代码 代码如下:

    %@ 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");
    //创建对象SqlConnection
    string strSQL="SELECT au_id,au_lname,au_fname,phone,address,city,zip FROM authors";
    SqlDataAdapter myCmd = new SqlDataAdapter(strSQL, myConn);
    //创建对象SqlDataAdapter
    DataSet ds = new DataSet();
    //创建对象DataSet
    myCmd.Fill(ds);
    //填充数据到Dataset
    DataView source = new DataView(ds.Tables[0]);
    MyDataGrid.DataSource = source ;
    MyDataGrid.DataBind();
    //将数据绑定到DataGrid
    }
    /script>
    body>
    h3>font face="Verdana">Simple SELECT to a DataGrid Control
    /font>/h3>
    ASP:DataGrid id="MyDataGrid" 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>
    您可能感兴趣的文章:
    • ASP.NET数据库编程之Access连接失败
    • asp.net程序优化 尽量减少数据库连接操作
    • asp.NET连接数的设置方法
    • ASP.NET 6种常用数据库的连接方法
    • ASP.NET中操作SQL数据库(连接字符串的配置及获取)
    • ASP.NET 连接ACCESS数据库的简单方法
    • ASP.NET连接SQL数据库的简单实例代码
    • ASP.NET连接MySql数据库的2个方法及示例
    • ASP.NET连接sql2008数据库的实现代码
    • ASP.NET oledb连接Access数据库的方法
    • asp.net通过配置文件连接Access的方法
    • asp.net快速连接access
    上一篇:ASP.NET加密口令的方法实例
    下一篇:VB.NET进度条的方法代码
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    在ASP.NET中连接SQL Server的简单方法 在,ASP.NET,中,连接,SQL,Server,