当前位置:编程学习 > C#/ASP.NET >>

asp.net如何连接数据库

asp教程.net如何连接数据库教程
下面是一款利用asp.net教程 c来连接mssql数据库,并查询出指定的数据哦。

string connstr = system.web.configuration.webconfigurationmanager.connectionstrings["sqlconnstr"].connectionstring;//这里
        sqlconnection conn = new sqlconnection(connstr);
        sqlcommand cmd = new sqlcommand();
        cmd.connection = conn;
        cmd.commandtext = "select id,xingming,gh from users where gh>600";
        try
        {
            conn.open();
            sqldatareader dr = cmd.executereader();
            this.gridview1.caption = "员工信息表";
            this.gridview1.datasource = dr;
            this.gridview1.databind();

        }
        catch (sqlexception gh)
        {
            throw gh;

        }
        finally
        {
            if (conn.state == connectionstate.open)
            {
                conn.close();
                       
            }
       
        }

    }

补充:asp.net教程,基础入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,