Smart DataReader!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, Whenever I use the SqlDataReader I have to retrieve a column by its
OrdinalPosition can't I do something like this

using(SqlDataRedaer sr=SqlHelper.ExecuteReader(....))
{
while(sr.Read())
string x=sr.GetValue("Column1").ToString();
// right now I have to do sr.GetValue(1).ToString();
}

TIA
 
Hi,

| Hi All, Whenever I use the SqlDataReader I have to retrieve a column by
its
| OrdinalPosition can't I do something like this
|
| using(SqlDataRedaer sr=SqlHelper.ExecuteReader(....))
| {
| while(sr.Read())
| string x=sr.GetValue("Column1").ToString();
| // right now I have to do sr.GetValue(1).ToString();
| }

try sr["Column1"]

Regarding the ToString() or in general converting the readed field to the
final type you have to do it always. The reason is that the indexer return
an object wich you need to cast (or convert) to your intended type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top