找不到列 [0] 运行时错误

本文关键字:运行时错误 找不到 | 更新日期: 2023-09-27 18:33:34

这是我的代码段。

DataSet ds = //assigning to dataSet from stored procedure
DataTable dt = ds.Tables[0]; // It has data i checked in debugging..

在运行时执行此操作时

Select("PGroup_strCode = O ")

它抛出了一个错误

"找不到列[O]" -- (我之前犯了一个错误,它不是提到的"O"零)

该列也存在。想不通原因。

更新:

Select("[Cinema_strID] = ABIC")

在选择部分中,我更改了此错误,现在错误是找不到列[ABIC]

找不到列 [0] 运行时错误

使用数据表选择语句时必须小心。

请尝试此

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

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

dt.Select("Cinema_strID = 'ABIC'")

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

    string searchVal =  "dummy ID"
    DataRow[] DataDR= ds.Tables[0].Select("ColoumnName= " + "'" + searchVal    + "'");
相关文章: