uma.n
uma.n

Reputation: 89

DataRow conversion issue in asp.net

How to convert system.data.datarow to an integer?

I Have a datarow which is returning the count of records which i want to store in an integer variable The statement is as follows

int TotalRecords=ds.Tables[1].Rows[0];

here ds is the DataSet.

when i am trying to write the above statement it is telling me that i cannot implicitly convert System.Data.DataRow to int

Upvotes: 1

Views: 921

Answers (2)

saille
saille

Reputation: 9191

You need to cast the value as an integer:

int TotalRecords = (int)ds.Tables[1].Rows[0]["YourColumnName"];

Upvotes: 1

Alexander Beletsky
Alexander Beletsky

Reputation: 19821

try that,

int TotalRecords=ds.Tables[1].Rows[0].Count();

you have to include Linq if not included

using System.Linq;

Upvotes: 0

Related Questions