SqlGetColumnInfo%

Gets the type, length, name, and server datatype of a specific column in the current set of results.

Syntax

SqlGetColumnInfo% ( sqlconn%, columndata, column% )

where

sqlconn%
Is a SQL Server connection. The value of sqlconn% is returned by SqlOpen%.
columndata
Is a user-defined datatype (structure), defined as ColumnData. It contains the following elements:
coltype%
Is an integer value for the datatype of a particular column. For the list of datatype token values, see "SqlColType%".
collen&
The maximum length of the column.
colname$
A string containing the name of a particular column. The string is 30 characters long.
colsqltype$
A string containing the name of the datatype used by SQL Server ¾ for example, int, smallint, and text. The string is 30 characters long.
column%
Is the number of the column. The first column is number 1.

Returns

SUCCEED (1) or FAIL (0). The column type, length, name, and SQL Server datatype are returned by the columndata parameter.

Remarks

SqlGetColumnInfo% performs the actions of several other DB-Library for Visual Basic functions and puts the results of those functions in the corresponding elements of the columndata parameter. SqlGetColumnInfo% is the equivalent of calling SqlColType%, SqlColLen%, and SqlColName$. To access the information about an element returned by columndata, you must use the point (.) notation:

columndata.elementname

For example, the following statement gets the column name returned by columndata:

ColumnName$ = columndata.colname$

You can call SqlGetColumnInfo% any time after you call SqlResults%.

Example

'Put command into the command buffer.
cmd$ = "SELECT title_id, price, advance FROM titles"
Result% = SqlCmd%(SqlConn%, cmd$)

'Send the command to SQL Server and start execution.
Result% = SqlExec%(SqlConn%)
Result% = SqlResults%(SqlConn)

'Get the column name, the datatype used by the server, and the maximum
'possible length of the data in the column and print the results.
IF Result% = SUCCEED THEN
   DO UNTIL Result% = NOMOREROWS
      Result% = SqlNextRow%(SqlColunn%)
       IF Result% = NOMOREROWS THEN Exit
 DO
       ELSE
          GetColumnInfo% = SqlGetColumnInfo%(SqlConn%,
         Dim ColDetail as ColumnData, Column%)
            IF GetColumnInfo% = SUCCEED THEN
               ColumnName$ = ColDetail.ColName$
               ColDatatype$ = ColDetail.ColSqlType$
               ColLength& = ColDetail.Collen&
               PRINT "Column name is "  ColumnName$
               PRINT "Datatype of column is "  ColDatatype$
               PRINT "Maximum possible length of data = "  ColLength&
               PRINT
            END IF
      END IF
   LOOP

See Also

SqlColLen%, SqlColType%, SqlColName$, SqlGetAltColInfo%