4

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?

Tim Post
  • 33,371
  • 15
  • 110
  • 174
James Andrew Cruz
  • 135
  • 1
  • 3
  • 9

3 Answers3

10
byte[] bits = Convert.ToByte(ds.Tables[0].Rows[0][0]);
Kamyar Nazeri
  • 25,786
  • 15
  • 50
  • 87
4

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]);
Preston Guillot
  • 6,493
  • 3
  • 30
  • 40
Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
3

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.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125