By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

use column name instead of index

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"msnews" <an******@yahoo.com> wrote in message
news:ek**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.