在Microsoft Access的单个参数中传递多个值 [英] pass multiple values in a single parameter in the Microsoft Access
问题描述
您好,我有一个带有Microsoft Access数据库的asp.net网站.我有一个产品表,其中包含多个类别,逗号与类别表分开.我需要获取所有相关类别的产品信息.我已经使用产品适配器创建了product.xsd.我使用了GetCategory(string categoryIds)函数,在其中传递了多个类别.问题是,当我在函数中传递单个类别时,它返回类别信息,但是当我传递多个类别时,它不返回任何记录.
这是代码
Hi, I have an asp.net web site with the Microsoft Access database. I have a product table, which contain the multiple categories with the coma seprated from the category table. I need to fetch the product information with all the respective category. I have created the product.xsd with the product adapter. I have used the GetCategory(string categoryIds) function, where I pass multiple categories. The problem is that, when I pass single category in the function its return the category information, however when I pass multiple categories then it does not return any record.
Here is the code
private string GetCategories(string categories)
{
categories = "'" + "C0004" + "','" + "C0005" + "'";
string categoryNames = string.Empty;
CategoryMasterTableAdapter obCategoryMasterTableAdapter = newCategoryMasterTableAdapter();
CategoryMasterDataTable categoryTable = newCategoryMasterDataTable();
categoryTable = obCategoryMasterTableAdapter.GetCategories(categories);
for (int iCount = 0; iCount < categoryTable.Rows.Count; iCount++)
{
CategoryMasterRow drow = categoryTable[iCount];
if (!String.IsNullOrEmpty(categoryNames))
{
categoryNames = "," + drow.CatDesc ;
}
else
{
categoryNames = drow.CatDesc;
}
}
return categoryNames;
}
表适配器查询为
Table Adapter query is
SELECT BookGroup, CatCode, CatDesc, CatTitle, ChildCatCode, ParentCatCode, UpdateStatus FROM CategoryMaster WHERE (CatCode IN (?))
谁能告诉我问题是什么或如何在单个参数中传递多个categoryid
[修改:将内联代码标记更改为前置标记]
can anyone tell me what is the problem or how to pass the multiple categoryids in a single parameter
[Modified: changed inline code tag to pre tag]
推荐答案
WHERE(CatCode IN(?))
WHERE (CatCode IN (?))
只需将CatCodes列表放在带有?的位置.例如:
Simply put the list of CatCodes where you have the ?. For example:
WHERE CatCode IN("C0004","C0005")
WHERE CatCode IN (''C0004'', ''C0005'')
参见 http://www.w3schools.com/sql/sql_in.asp [
See http://www.w3schools.com/sql/sql_in.asp[^] for an example.
这篇关于在Microsoft Access的单个参数中传递多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!