求助大神 SQL怎么在C#里面用不了LIKE查询

请帮帮忙图片说明图片说明string select_sql;
string connect_sql = "Data source=.; initial catalog=project; integrated security=true";
select_sql = "use project select ISBN,BKNAME,AUTHOR,PUBLISHER,PRICE,CNUM,SNUM from book where @libname LIKE bkname";
SqlConnection sc = new SqlConnection(connect_sql);
SqlCommand cmd = new SqlCommand(select_sql, sc);
SqlParameter snoparam = new SqlParameter("@libname", textBox1.Text);
cmd.Parameters.Add(snoparam);
SqlDataAdapter da = new SqlDataAdapter();
// da.Fill(ds, "grde");
da.SelectCommand = cmd;
DataSet pro = new DataSet("project");
pro.Tables.Add("jy");
da.Fill(pro, "jy");
dataGridView1.DataSource = pro.Tables["jy"];
sc.Close();


3个回答

 select_sql = "use project select ISBN,BKNAME,AUTHOR,PUBLISHER,PRICE,CNUM,SNUM from book where @libname LIKE bkname";
->
select_sql = "select ISBN,BKNAME,AUTHOR,PUBLISHER from book where bkname LIKE '%@libname%'";
wzdjsgf
wzdjsgf 还是不行啊 。。。
4 年多之前 回复

LIKE后的要用到单引号或者通配符

定义的sql查询字符串写的有问题,应改为
select_sql = "select ISBN,BKNAME,AUTHOR,PUBLISHER from book where bkname LIKE '@libname'"
bkname和@libname的位置要换一下,并加引号,bkname为对应sql里的子段名字,后者为引用的值

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问