|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading Field/Column Names using VB
Hi, I'm trying to read from MS Access the field names from a table.
How can I do this in VB. I've been trying with out success. thanks, |
|
#2
|
||||
|
||||
|
Code:
dim i as integer
dim cnConnection as adodb.connection
dim rsRecordset as adodb.recordset
dim aryFields() as string
set rsrecordset = new adodb.recordset
set cnConnection = new adodb.connection
'...Database connection stuff
'redeclare array boundaries with ubound being number of fields names
redim aryFields(rsRecordset.fields.count) as string
'loop through field names and capture field names in array
For i = 0 To (rsRecordset.Fields.Count - 1)
aryfields(i) = cstr(trim(rsRecordset.Fields.Item(1).Name))
Next i
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein Last edited by Fisherman : October 22nd, 2003 at 10:03 AM. |
|
#3
|
|||
|
|||
|
Thanks I will surely try this. Thanks ahead of time.
|
|
#4
|
|||
|
|||
|
Fisherman!U are welcome...U always give a people who need helped some way to though the trouble!..
|
|
#5
|
|||
|
|||
|
trying
Thanks for the tip. I've been trying to work in your code with what I already have. Since this is a total separate functionallity, I shouldn't have problem with your code.
I've tested what you have given me and when it gets to the loop, right away it steps out of the loop and does not continue. By the way must of been a little type. on your redeclaration you have: redim aryfields(rsbalancer .fields.count -1) shouldn't it be: redim aryfields(rsRecordset .fields.count -1) I changed it on mine but just thought you'de like to change. thanks again. |
|
#6
|
||||
|
||||
|
sorry about that.. My boss would kill me if he saw that. I pulled that code directly from a project I did a few months ago where I pulled data from SQL Server, graphed it, and put it into a report in excel. I tried to replace all the references with generic ones, but I guess I missed one.
|
|
#7
|
||||
|
||||
|
I dont' know why it would step over the loop. Try breakpointing it and checking the value of (rsRecordset.fields.count-1) at run time. Obviously, you'll have to change the name of rsRecordset to whatever your active, working recordset is, or you'll have to pass in a recordset byref to a function that handles this processing for you.
|
|
#8
|
|||
|
|||
|
Hi, mighty_mouse! Before u breakpoint your code which is runing on your machine,U can print your recordset.fields.count to screen.Maybe u can find some..
|
|
#9
|
|||
|
|||
|
It's possible your recordset doesn't support the recordcount property, not all recordsets do.
Try using a for each loop. Code:
<% dim fld For Each fld in rs.Fields response.write fld.name Next %> |
|
#10
|
||||
|
||||
|
ahh.. yes - forgot about the horrible rsrecordset.recordcount = -1... must remember to use cursorlocation=aduseclient and cursortype = adopendynamic on that POS problem
|
|
#11
|
|||
|
|||
|
THNX!!!!!!!
Thank you guys. I got it working!!!!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Reading Field/Column Names using VB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|