求高手看看什么错误
源代码如下:
String connString = @"Data Source=lusson-PC\SQLEXPRESS; AttachDbFilename=|DataDirectory|\alpine.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True";
String sql = @" SELECT * FROM cars WHERE " + Label1.Text;
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);
DataSet testDataSet = new DataSet();
adapter.Fill(testDataSet, "result_data");
conn.Close();
foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows)
{
Console.WriteLine("id:{0} ; make:{1} ; model:{2} ",
testRow["id"], testRow["make"], testRow["model"]
);
}
编译没有错误,数据库连接成功,网页执行出错,错误信息如下:
Server Error in '/asp' Application.
Incorrect syntax near '='.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Source Error:
Line 35: SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);
Line 36: DataSet testDataSet = new DataSet();
Line 37: adapter.Fill(testDataSet, "result_data");
Line 38: conn.Close();
Line 39:
Source File: e:\stclaircollege\semester6\final project\asp\makes.aspx.cs Line: 37
求高手给看看,语法哪里有错,说是在等于号附近, 找了半天没找出来,郁闷
先谢了