Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my C# code?

Tags:

c#

.net

datarow

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.

Where did I go wrong?

like image 784
James Andrew Cruz Avatar asked Dec 03 '22 05:12

James Andrew Cruz


2 Answers

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);
like image 129
Kamyar Nazeri Avatar answered Dec 24 '22 02:12

Kamyar Nazeri


Item is not an indexer, it's a function. 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:

byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);
like image 45
Saeed Amiri Avatar answered Dec 24 '22 02:12

Saeed Amiri