Request["id"]和数据库查询的问题
SqlConnection con = new SqlConnection("server=localhost;database=bbs;uid=sa;pwd=''");
con.Open();
string sql = "select * from discuss where topicNo= "+Request["id"];
SqlCommand comm = new SqlCommand(sql ,con);
SqlDataReader dr = comm.ExecuteReader();
报错:
Exception Details: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。
Source Error:
Line 19: string sql = "select * from discuss where topicNo= "+Request["id"];
Line 20: SqlCommand comm = new SqlCommand(sql ,con);
Line 21: SqlDataReader dr = comm.ExecuteReader();
Line 22: try
Line 23: {
单独 string sql = "select * from discuss where topicNo= 1“是没有问题的
为什么Request["id"]加上后就出问题了啊