About Columns

Posted on 2004-08-02
Last Modified: 2010-04-17
Hi !

I want some function which is equivalent to SQLNumResultCols( ) in VB, since iam using ADODB.
Also i want to count the Column Length of a table, how can i do ?

Can someone help me with a piece of code please.... would be much helpful..

Question by:raghx_2000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 11701562
You could put your adodb recordset results in to variant array which would give you the ability to count the rows. The method is getRows as shown below. If you stuffed this into a function then for each recordset you return you can count through the array dimension and get you column count / row count etc.

Dim objRs As New ADODB.Recordset
Dim objCmd As New ADODB.Command
Dim objConn As New ADODB.Connection
objConn.Open strDbConnectionString
objCmd.CommandText = strSQL
objCmd.CommandType = adCmdText
Set oCmd.ActiveConnection = objConn
ObjRs.Open oCmd

MethodName = objRs.GetRows
dim i as integer
for i = 0 to uBound(MethodName)
  'do what you want with your array data in here such as count the number of columns

Set objRs= Nothing
Set objCmd= Nothing
Set objConn= Nothing



Expert Comment

ID: 11715635
objRs.Fields.count is also preferable in this way.

Author Comment

ID: 11750548
I think some mistake here !

I dont want to count columns, i want to count the length of each column in a table.
Ex: if i have a columns like this in table XXX then
Column name  Datatype Lenght
Name             VArchar  12
Id                   Numeric 6
Then i must count the length....
How .... ?
any code sample will do....

Accepted Solution

johanmulder earned 20 total points
ID: 11750596
O Right, got it now :)

there is a propertie of a column, the DefinedSize propertie, which returns the defined length of your field:


 If this one fails VB will return the value of the ActualSize propertie instead (which is de actual size of the stored data itself).

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question