473,408 Members | 1,753 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,408 software developers and data experts.

Data Binding and Field Names

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
2 1287
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: 'bonehead | last post by:
Greetings, I'd like to figure out some syntax for retrieving the data from a table when I don't know all the of field names. What I do know are, the name of the table, the names of the primary...
5
by: David Gray | last post by:
Greetings all, How can I use ADODB to return all tables in an access DB chosen by the user? I'm able so far to select the DB file and build up my connect string, but I would like to offer a...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
2
by: John Sun | last post by:
Hi, Dear gurus, I want to bind my collection to a datagrid. The field names in my object show up in a weird order, and I just wonder how I could reorder those columns . I find some code like...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
3
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a...
2
by: Neo | last post by:
I put a similar post for CheckBoxes, but i want to use a Radio button & not a CheckBox I have a field named "Male" & this is of SQL BIT data type (SQL Server). How can i bind this field to a...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.