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

Data Binding and Field Names

P: n/a
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 casemast where id=inid)

lots of data in a medical records system - I'm hoping I don't need to
create a class + parameters + etc.

I know that the field names can be displayed in a DataGrid - I don't
know how to get them otherwise - I'll use any data structure that will
let me get the names!

(I've seen lots of examples of how to read them from a datareader after
you define the fields yourself.)

Is there a data structre that supports this?

Thanks very much,

Fred

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can iterate through the DataColumns of a DataTable or you can use the
GetName method of the DataReader. See the code below.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
Dim cn As New SqlConnection("Server=(local);Database=pubs;Integr ated
Security=SSPI;")
Dim da As New SqlDataAdapter("SELECT * FROM Authors", cn)
Dim dt As New DataTable
da.Fill(dt)
For Each dc As DataColumn In dt.Columns
ListBox1.Items.Add(dc.ColumnName)
Next

Dim dr As SqlDataReader
Dim i As Integer
cn.Open()
dr = da.SelectCommand.ExecuteReader(CommandBehavior.Clo seConnection)
For i = 0 To dr.FieldCount - 1
ListBox2.Items.Add(dr.GetName(i))
Next
dr.Close()

"Fred Nelson" <fr**@smartybird.com> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
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 casemast where id=inid)

lots of data in a medical records system - I'm hoping I don't need to
create a class + parameters + etc.

I know that the field names can be displayed in a DataGrid - I don't
know how to get them otherwise - I'll use any data structure that will
let me get the names!

(I've seen lots of examples of how to read them from a datareader after
you define the fields yourself.)

Is there a data structre that supports this?

Thanks very much,

Fred

Nov 20 '05 #2

P: n/a
Rob Windsor [MVP] wrote:
You can iterate through the DataColumns of a DataTable or you can use the
GetName method of the DataReader. See the code below.

Rob:

Thanks very much for showing me this - this is EXACLTY what I was
looking for!

Fred
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.