簡體   English   中英

我的C#代碼出了什么問題?

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

這里的代碼有問題:

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

有一個錯誤說:

System.Data.DataRow不包含'Item'的定義,也沒有擴展方法'Item'可以找到類型'System.Data.DataRow'的第一個爭論。

我哪里做錯了?

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

Item不是索引器,它是一個函數。 你應該做:

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

或者如果你想在table0中的0,0位置處設置項目,你可以:

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

采用:

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

ds.Tables[0].Rows[0]返回DataRow ,它具有索引器this[int] ,它返回按索引存儲在列中的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM