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