读书人

ASP .NET 链接SQL解决思路

发布时间: 2013-04-21 21:18:07 作者: rapoo

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引号

读书人网 >asp.net

热点推荐