use column name instead of index

  • Thread starter Thread starter msnews
  • Start date Start date
M

msnews

Hi All,

I have the following code

----------------------------------------------------
Business.Product pdt = new Business.Product();
SqlDataReader product = pdt.GetProductDeals(134);

StringBuilder maker = new StringBuilder();
while (product.Read())
{
maker.append ("formatting text" + product.GetValue(8).ToString());
maker.append ("formatting text" + product.GetValue(3).ToString());
maker.append ("formatting text" + product.GetValue(12).ToString());
}

----------------------------------------------------

In the above code, I am using index value to get the database column value.
It's causing lot of confusion as I have around 45 fields coming from
database. Is it possible to use the DB Column name instead of index value.

Please help.

Thanks in Advance.
 
Hi,

You can use indexer method in DataReader
eg product["myprodutcode"]

I havent wrote this piece of code to check that it works
But, this is based on the documentation

HTH
Kalpesh
 
You can write a utility method that will take a column name as a parameter
and then find the matching column with the SqlDataReader.GetName () method.

Eliyahu
 

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