4

This is my piece of code.

DataSet ds = //assigning to dataSet from stored procedure

DataTable dt = ds.Tables[0]; // It has data i checked in debugging..

when doing this operation in run time

Select("PGroup_strCode = O ")

It s throwing an error

"Cannot find Column[O]" -- ( i made a mistake earlier it is 'O' not zero as mentioned earler )

That column is also present. Can't figure it out the reason.

UPDATE :

Select("[Cinema_strID] = ABIC")

In select part i changed this now error is Cannot find Column[ABIC]

4

3 回答 3

5

使用 Datatable 选择语句时必须小心。

请试试这个

DataRow[] DataDR= ds.Tables[0].Select("[Cinema_strID]='ABIC'");

或者

DataRow[] DataDR= ds.Tables[0].Select(ds.Tables[0].Columns[1].ColumnName.Trim()+"='ABIC'"); // But this is only when you are sure that the column position wont change in the future
于 2013-10-01T06:26:05.733 回答
1

虽然这是一个老问题,但可以帮助任何未来的访问者:如果它是一个字符串,您需要提供值以过滤单引号/撇号,即'ABIC'

dt.Select("Cinema_strID = 'ABIC'")
于 2020-07-02T09:30:21.627 回答
0

如果列内容是整数,您的代码会起作用。如果是字符串,您应该执行以下操作

    string searchVal =  "dummy ID"
    DataRow[] DataDR= ds.Tables[0].Select("ColoumnName= " + "'" + searchVal    + "'");
于 2016-12-16T07:49:45.743 回答