What is wrong with my C # code?

Something is wrong with my code here:

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

It says an error:

System.Data.DataRow does not contain a definition for "Item" and no the extension method "Element" that takes the first argument of type 'System.Data.DataRow can be found.

Where am I wrong?

+4
source share
3 answers
 byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]); 
+10
source

The item is not an index, it is a function. You must do:

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

Or, if you want the position at position 0,0 in your table0 you would do:

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

Using:

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

ds.Tables[0].Rows[0] returns a DataRow with index this[int] , which returns the data stored in the column by index.

+3
source

Source: https://habr.com/ru/post/1397260/


All Articles