473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

can i get a list of field names in a SqlDataReader ?

Hi guys

Ok, here's the situation. I'm building a reporting system for my
application, that basically creates a CSV file based on a load of data in my
database.

I'm trying to make the application as "extensible" as possible, by not
hardcoding anything. So I'm thinking you can select a report type, and that
runs a peice of code that runs a stored proceedure and puts the results into
a CSV.

I suppose the first question is "is there an easy to way to do that that I
haven't found yet?".

My idea is to simply go through the data reader and dump everytihng to CSV,
the problem is.. I can't do that cos I won't know how many fields there are.
Can I find that out from the DataReader, and can I grab the field names from
the DataReader so that I can put these at the top of my CSV?!

Any help/ideas appreciated!

Cheers

Dan
Nov 19 '05 #1
2 1856
Hi Dan,
My idea is to simply go through the data reader and dump everytihng to
CSV,
the problem is.. I can't do that cos I won't know how many fields there
are.
Can I find that out from the DataReader, and can I grab the field names
from
the DataReader so that I can put these at the top of my CSV?!
Yes, you can, and yes there is.

A DataReader has the following properties and methods for retrieving column
information:

FieldCount - returns the number of columns in the result set.
GetFieldType(int) - returns the Type of the column.
GetDataTypeName(int) - returns the Name of the back-end database column
type.
GetName(int) - returns the Column Name.

So you would start by getting the FieldCount, and create a loop to loop
through the Fields (columns) in the DataReader, getting whatever information
you need about each one.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"dhnriverside" <da*@musoswire.com> wrote in message
news:27**********************************@microsof t.com... Hi guys

Ok, here's the situation. I'm building a reporting system for my
application, that basically creates a CSV file based on a load of data in
my
database.

I'm trying to make the application as "extensible" as possible, by not
hardcoding anything. So I'm thinking you can select a report type, and
that
runs a peice of code that runs a stored proceedure and puts the results
into
a CSV.

I suppose the first question is "is there an easy to way to do that that I
haven't found yet?".

My idea is to simply go through the data reader and dump everytihng to
CSV,
the problem is.. I can't do that cos I won't know how many fields there
are.
Can I find that out from the DataReader, and can I grab the field names
from
the DataReader so that I can put these at the top of my CSV?!

Any help/ideas appreciated!

Cheers

Dan

Nov 19 '05 #2
Wow - that's very helpful. Just written the whole function now with that
little bit of advice.

Thanks Kevin - I owe you some beer!
"Kevin Spencer" wrote:
Hi Dan,
My idea is to simply go through the data reader and dump everytihng to
CSV,
the problem is.. I can't do that cos I won't know how many fields there
are.
Can I find that out from the DataReader, and can I grab the field names
from
the DataReader so that I can put these at the top of my CSV?!


Yes, you can, and yes there is.

A DataReader has the following properties and methods for retrieving column
information:

FieldCount - returns the number of columns in the result set.
GetFieldType(int) - returns the Type of the column.
GetDataTypeName(int) - returns the Name of the back-end database column
type.
GetName(int) - returns the Column Name.

So you would start by getting the FieldCount, and create a loop to loop
through the Fields (columns) in the DataReader, getting whatever information
you need about each one.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"dhnriverside" <da*@musoswire.com> wrote in message
news:27**********************************@microsof t.com...
Hi guys

Ok, here's the situation. I'm building a reporting system for my
application, that basically creates a CSV file based on a load of data in
my
database.

I'm trying to make the application as "extensible" as possible, by not
hardcoding anything. So I'm thinking you can select a report type, and
that
runs a peice of code that runs a stored proceedure and puts the results
into
a CSV.

I suppose the first question is "is there an easy to way to do that that I
haven't found yet?".

My idea is to simply go through the data reader and dump everytihng to
CSV,
the problem is.. I can't do that cos I won't know how many fields there
are.
Can I find that out from the DataReader, and can I grab the field names
from
the DataReader so that I can put these at the top of my CSV?!

Any help/ideas appreciated!

Cheers

Dan


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Melissa Kay Beeline | last post by:
OK, here's the sitch : we have an access control system at work that registers ever entry/exit of every employee. I recently made some queries in Access so the ppl in HR could make reports (who...
7
by: dixie | last post by:
I have a text box on a form. In that text box is a list of people separated by a comma. Like A.Smith, L.Jones, P.Somebody, H. Somebodyelse Note, there is no full stop at the end of the list...
2
by: Fred Nelson | last post by:
I have an app I'm working on where I would like to be able to access the field names that are returned by a stored procedure. My stored procedure will return about 140 fields (select * from...
0
by: member | last post by:
Hi, Good day.i need some help from you guys. I'm using vb.net and sql database to build my file. The purpose of this file is to view news based on deparment. Im using listbox and radiobutton...
5
by: Tom Edelbrok | last post by:
I notice that using the SqlDataReader requires the use of ordinal field references rather than by name. For example, do while (myDataReader.Read())...
2
by: Tomdhu | last post by:
I've got a Contacts & Events database in Access 2K where contacts attend various events. At present, where I want to group e-mail all the attendees who are going to attend a particular event, I...
4
by: justin tyme | last post by:
Hello Experts! I would like to combine (which may not be the correct technical term) two text fields from the same table in a query. Specifically, text field A and text field B are both lists of...
0
by: webmaster | last post by:
Pardon my being a total C# noob. I'm trying to take apart the dotNet Time Tracker dotNet C# starterkit sample application and replicate a part of the code. At a high level, I have a very...
11
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.