我的C#代码有什么问题?

4

这里我的代码有问题:

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0].Item[0]);

出现了一个错误:

System.Data.DataRow没有包含“Item”的定义,也没有找到任何扩展方法“Item”接受类型为“System.Data.DataRow”的第一个参数。

我错在哪里了?

3个回答

10
byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);

4

该项不是索引器,而是一个函数。您应该进行如下操作:

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0].Item(0));

如果你想要获取表格中位置为0, 0的元素,可以使用以下方法:

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);

3

使用:

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);

ds.Tables[0].Rows[0] 返回一个 DataRow,它有一个索引器 this[int],可以通过索引返回列中存储的数据。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接