我用C#进行图书的查询,语句如下,
private void button1_Click(object sender, EventArgs e)
{
string booknametext = "%" + bookName.Text + "%";//单引号或双引号一样的
this.stockSearchTableAdapter.Fillbybookidandt(this.bookstoreDataSet.stockSearch, booknametext,dateTimePicker1.Value.ToString(),dateTimePicker2.Value.ToString());
}
可是问题是,比如书名booknametext是: “JAVA基础知识”,我在文本框里输入“基础”两个字,就查不出来,必须是%%%基础%%%,这样才能查出来,是不是%不能做模糊查询啊?不能用作通配符? 问题出在哪里呢,请大侠指点
可是我的where语句是在Tableadapter里面写的,按照上面的语法,我是在Tableadapter里不成功的,
如下是TableAdapter里面的带参数的查询语句
你看里面的@x变量,这该怎么办,难道写成‘%“+@x=”%’ 这样写,在Tableadapter里面也是不能成功实现查询的? 还请多指点
SELECT book_info.图书ID, book_info.图书名称, book_info.作者, book_info.出版社, book_info.出版时间, book_info.简介, stock_info.库存ID, stock_info.库存数量, stock_info.库存单价, stock_info.库存金额 FROM book_info INNER JOIN
stock_info ON book_info.图书ID = stock_info.图书ID
WHERE (book_info.图书名称 LIKE @x) AND (book_info.出版时间 BETWEEN @t1 AND @t2) OR
(book_info.出版时间 BETWEEN @t1 AND @t2) AND (book_info.作者 LIKE @x) OR
(book_info.出版时间 BETWEEN @t1 AND @t2) AND (book_info.出版社 LIKE @x)
改一下 query
WHERE CharIndex(@x, book_info.图书名称) > 0
试试 不要加%
是这样,like 不做很高要求的时候,用CharIndex作为替代。。。
谢谢,真是一代大侠!
最终查询语句应该是where BookName like '%'"+ bookName.Text + "'%'
可是我的where语句是在Tableadapter里面写的,按照上面的语法,我是在Tableadapter里不成功的,
你看里面的@x变量,这该怎么办,难道写成‘%“+@x=”%’ 这样写,在Tableadapter里面也是不能成功实现查询的? 还请多指点
SELECT book_info.图书ID, book_info.图书名称, book_info.作者, book_info.出版社, book_info.出版时间, book_info.简介, stock_info.库存ID, stock_info.库存数量, stock_info.库存单价, stock_info.库存金额 FROM book_info INNER JOIN
stock_info ON book_info.图书ID = stock_info.图书ID
WHERE (book_info.图书名称 LIKE @x) AND (book_info.出版时间 BETWEEN @t1 AND @t2) OR
(book_info.出版时间 BETWEEN @t1 AND @t2) AND (book_info.作者 LIKE @x) OR
(book_info.出版时间 BETWEEN @t1 AND @t2) AND (book_info.出版社 LIKE @x)
like '%"+ bookName.Text + "%'
改成如下,string booknametext ="'%"+bookName.Text+"%'"; 也还是不行的,郁闷,求解啊
楼上正解