Simple (I guess) SQL question...

JustAGuy
10-13-2004, 08:59 PM
Hi There,

I am writing a SQL coder to an application, loaded in the tag property, this way:

Set rs = New ADODB.Recordset
rs.Open Me.Tag, Conn

I would like to know how can I get from the recordset:

- how much fields was been returned
- the type, name and length of the fields

Thanks!

NEOLLE
10-13-2004, 09:51 PM
Set rs = New ADODB.Recordset
rs.Open Me.Tag, Conn

I would like to know how can I get from the recordset:

- how much fields was been returned
- the type, name and length of the fields


Hello,
Your Open Recordset statement is incomplete

rs.Open Me.Tag, Conn,AdOpenForwardOnly,AdLockReadOnly


The Number of fields returned depends on you Query statement. If you say "SELECT * FROM Table1", then the query will return all the fields your Table1 contain. But if you say "SELECT Field1,Field2 FROM Table1" then it is obvious that your query will return 2 Fields. Another example is "SELECT Field1,Field2,Count(*) FROM Table1 WHERE ..." will return 3 fields.

But if you mean the Number of Records returned, you can use the Recordset.RecordCount Property.

The type and length of the fields can be seen using this statement
"DESC Table1". This statement will show the list of all the fields in Table1, including it type and length.

Have Fun :)

JustAGuy
10-14-2004, 06:09 AM
Hey,

Thanks for the help, but I think that I wasnt so much explicit, so you cant understand what I need!

Let's see:

1) I KNOW that the fields that will be returned will depend on the query (* for all, etc), but, in fact, I DONT KNOW which fields will be returned because I am writing an application that will run an user query. This way, I dont know WHAT the user will type, then even he will use the *, the number of fields will be depend on which table he will query.

2) I dont need the recordcount, but a kind of "field count".

3) I need:

a) the number of fields returned in the query
b) the name of the fields returned in the query
c) the type and length of the fields returned in the query

4) You told me that my statement is incomplete...

What's the difference between:

rs.Open Me.Tag and
rs.Open Me.Tag, Conn,AdOpenForwardOnly,AdLockReadOnly ???

Thanks!

NEOLLE
10-14-2004, 06:33 AM
Ok here goes.
You RecordSet Object has a list of properties. I wont be naming all, just a few :D


'----To find the numbers of fields returned use
objRecordSet.Fields.Count

'----To find the names of the fields returned use
objRecordSet(Index).Name


To view all the propties use VB Watch Window Tool.
Goto View--> Watch Window. :)

JustAGuy
10-14-2004, 09:37 AM
Hey, thanks again!
I was just found out the solution, moments before receive your response.
Here it goes:

rs.Fields.Count > get the number of fields
rs.Fields(n).Name > get the name of the n field
rs.Fields(n).Value > get the content of the n field
rs.Fields(n).DefinedSize > get the size of the n field
rs.Fields(n).Type > get the type of the n field

Very usefull!

By the way, you didnt answered me...

What's the difference between

rs.Open Me.Tag, Conn
rs.Open Me.Tag, Conn,AdOpenForwardOnly,AdLockReadOnly

I mean, what's the difference in ommit the "AdOpenForwardOnly,AdLockReadOnly" ????

Thanks a lot!

Granty
10-14-2004, 09:41 AM
In that example I dont think there is a difference as the 2 parameters Noelle supplies are the default ones if you omit them (I believe :P)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum