Solved

About Columns

Posted on 2004-08-02
6
210 Views
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..

Regards
0
Comment
Question by:raghx_2000
  • 2
6 Comments
 
LVL 1

Expert Comment

by:bwh1te
Comment Utility
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
next

objRs.Close
objConn.Close
Set objRs= Nothing
Set objCmd= Nothing
Set objConn= Nothing


 

0
 
LVL 1

Expert Comment

by:johanmulder
Comment Utility
objRs.Fields.count is also preferable in this way.
0
 
LVL 3

Author Comment

by:raghx_2000
Comment Utility
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....
0
 
LVL 1

Accepted Solution

by:
johanmulder earned 20 total points
Comment Utility
O Right, got it now :)

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

 objRs.Fields(1).DefinedSize

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now