首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ASP .NET 链接SQL解决思路

2013-04-21 
ASP .NET 链接SQL主方法protected void Page_Load(object sender, EventArgs e){try{if (!IsPostBack){sql

ASP .NET 链接SQL
主方法
protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                sqlConnectionOpen();         
}
        }
        catch (SqlException ex)

        {
            Response.Write("IO.exception:" + ex.Message);//报错消息为IO.exception:'‘' 附近有语法错误。字符串 '' 后的引号不完整。  
        }
    }

sqlConnectionOpen()方法:
protected void sqlConnectionOpen()
    {
        
        string ConnectionString = "Server=(local);database=BMS;Trusted_Connection=yes";
        SqlConnection Conn = new SqlConnection(ConnectionString);
        SqlCommand comm = new SqlCommand("select * from customer where CustomerName=‘章宇'", Conn);
        Conn.Open();
        SqlDataReader myReader = comm.ExecuteReader();
        while (myReader.Read())
        {
            label1.Text = myReader.GetString(0);
            label2.Text = myReader.GetString(1);
            label3.Text = myReader.GetString(2);
            label5.Text = myReader.GetString(3);
            label4.Text = myReader.GetString(4).ToString();

        }
    }
我看得眼都瞎了,坐等大神
SQL .NET ASP
[解决办法]
章雨前面的单引号是全角的,改成半角
[解决办法]
章宇左边的引号是chinese引号
[解决办法]
章宇右边的引号是chinese引号

热点排行