如何使用两个变量值从数据表中选择一行? [英] How can I select a row from a datatable using two variable values?

查看:120
本文介绍了如何使用两个变量值从数据表中选择一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我在这里要做的是从数据表中选择与两个变量匹配的所有行.首先,我将SPList查询到数据表中.数据表有两列,客户端ID和模型详细信息.这是一些代码,因此希望您能对我的尝试有所了解.

Alright, so what I'm attempting to do here, is select from a datatable all the rows that match two variables. First, I queried a SPList into a datatable. The datatable has two columns, Client ID, and Model Details. Here's some of the code, so hopefully you can get an idea of what I'm attempting.

//These are contained within a foreach loop, so will be different through each
//iteration through.
int iClientID = gdbData.GetClientID(iJobNumberID);
string strModelDetails = xeApprovalUpdate.GetAttribute("ModelDetails");
string strClientID = iClientID.ToString()
//Here my datatable is populated from the sharepoint list I query
DataTable dtabModelDetails = queryModelDetails(splModelDetails);
DataRow[] drModelDetails = dtabModelDetails.Select(strClientID, strModelDetails);

看到那行不通,我尝试执行以下选择语句:

Seeing as that didn't work, I attempted to do the following select statement:

DataTable dtabModelDetails = queryModelDetails(splModelDetails);
string strDataExpression = "ClientID = " + strClientID + " AND Title = " + strModelDetails;
DataRow[] drModelDetails = dtabModelDetails.Select(strDataExpression);

现在我在选择语句时遇到语法错误,但是我很确定我的语法是正确的吗?如果我的select语句不返回任何行,我会收到此错误吗?

Now I'm getting a syntax error for the select statement, but I'm pretty sure my syntax is correct? Would I get this error if my select statement returned no rows?

推荐答案

是的,您可以像这样...将where子句添加到DataTable Select方法中.

Yes, you can add where clause to the DataTable Select method like this....

DataRow[] drModelDetails = dtabModelDetails.Select("Client ID = '" + clientId + "' AND Model Details = '" + modelDetails + "'");

这篇关于如何使用两个变量值从数据表中选择一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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