简体   繁体   English

我的C#代码出了什么问题?

[英]What's wrong with my C# code?

There is something wrong with my code here: 这里的代码有问题:

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

There's an error saying that: 有一个错误说:

System.Data.DataRow does not contain a definition for 'Item'and no extension method 'Item' accepting a first arguement of type 'System.Data.DataRow could be found. System.Data.DataRow不包含'Item'的定义,也没有扩展方法'Item'可以找到类型'System.Data.DataRow'的第一个争论。

Where did I go wrong? 我哪里做错了?

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

Item is not an indexer, it's a function. Item不是索引器,它是一个函数。 You should do: 你应该做:

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

Or if you want item at 0,0 position in your table0 you can do: 或者如果你想在table0中的0,0位置处设置项目,你可以:

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

Use: 采用:

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

ds.Tables[0].Rows[0] returns DataRow which has indexer this[int] which returns data stored in the column by index. ds.Tables[0].Rows[0]返回DataRow ,它具有索引器this[int] ,它返回按索引存储在列中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM