在数据库的不同列中查找字符串 [英] Finding string in different columns in database

查看:82
本文介绍了在数据库的不同列中查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个简单的问题.我需要在数据库中找到一些字符串.

我有一个表名Product.具有以下属性.

1)产品编号
2)产品条形码
3)产品名称
4)产品说明
5)产品价格

我的问题是我创建了数据行,并希望从数据库中输入值,但使用列(产品条形码)进行搜索.

Hi
I have simple problem. I need to find some string in a database.

I have a table name Product. which has the following attributes.

1)Product ID
2)Product Bar code
3)Product Name
4)Product Description
5)Product Price

My question is i created the data Row and want to put in the value from a database but search it using columns(Product Bar code).

DataRow addproduct = dS_product1.Tables["Product"].Columns????????;


谢谢
Waleed Hassan


Thanks
Waleed Hassan

推荐答案

要基于条形码过滤行,可以使用Select方法,请参见: ^ ].

因此,您的查询可能类似于
To filter the rows based on bar code, you can use the Select method, see: DataTable.Select Method (String)[^].

So your query could be something like
DataRow[] addproduct = dS_product1.Tables["Product"].Select("BarCode = '...'");



有关可以在选择项中使用的表达式的更多信息,请参见 DataColumn.Expression属性 [^ ].即使标题说它是针对DataColumn的,相同的表达式也适用于select语句



For more information about the expressions you can use in the select, see DataColumn.Expression Property[^]. Even though the title says that it''s for DataColumn, the same expressions apply in a select statement


DataRow addproduct = dS_product1.Tables ["Product"].Columns? ??????;
试试:
DataRow addproduct = dS_product1.Tables["Product"].Columns????????;
Try:
// Access each row and then columns of that row
foreach(DataRow dr in dS_product1.Tables["Product"])
{ 
  productID = dr["ProductID"].ToString();
  productNme = dr["ProductName"].ToString()
  // like wise others
}


这篇关于在数据库的不同列中查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆