使用 DataSet 在数据库上搜索值时出现问题,WHERE LIKE 不起作用

问题描述 投票:0回答:1

Visual Basic、Visual Studio 2022。本地 mdf 数据库,Visual Studio 自带的基于服务的数据库。

我有一个显示表格的 DataGridView 和一个用于搜索值的文本框。 数据集具有此查询“SearchInventory”(使用 Query Configuration Wizard 创建):

SELECT        id, name, [desc], price
FROM            tableInventory
WHERE        (name LIKE '%' + @Param1 + '%')

使用查询配置向导测试它是否完美运行。

但是,当我使用TextBox进行搜索时

InventoryTableAdapter.SearchInventory(InventoryDataSet.inventoryTable, txtSearch.text)

它只显示完全匹配时的值,基本上忽略“LIKE”指令。使用预览数据来测试也不起作用。

用固定值替换参数,“铲除”预览数据和 DataGridView 按预期显示值

SELECT        id, name, [desc], price
FROM            tableInventory
WHERE        (name LIKE '%shovel%')
database vb.net visual-studio
1个回答
0
投票

查询没有错误。 调用查询的代码没有错误。 或者它们是(?),WHERE LIKE 不起作用,您必须使用此视频

中解释的 Filter 属性
© www.soinside.com 2019 - 2024. All rights reserved.