SqlData$

Returns a string containing data in a result column.

Syntax

SqlData$ ( sqlconn%, column% )

where

sqlconn%
Is a SQL Server connection. The value of sqlconn% is returned by SqlOpen%.
column%
Is the number of the result column. The first column is number 1.

Returns

A string containing the data in a result column. For the SQL Server datatypes binary, varbinary, and image, SqlData$ returns a string of binary data, with one character in the string per byte of data in the result column. For all other datatypes, SqlData$ returns a string of readable characters. When there is no such column or when the data is NULL, an empty string is returned. To make sure that the data really is NULL, always check for a return of 0 by using SqlDatLen&.

Remarks

Use SqlDatLen& to get the length of the data for variable-length datatypes. For numeric datatypes, use the Visual Basic LEN function to determine the length of the string returned by SqlData$.

To convert the data from a string to a different datatype, use SqlColType% to get the datatype of the data, then use Visual Basic functions to convert to Visual Basic datatypes. Some helpful Visual Basic conversion functions are shown in the following table. For more information, see your documentation for Visual Basic.

Visual Basic
function

Description
CDBL Converts a numeric expression to a double-precision value.
CLNG Converts a numeric expression to a long integer.
VAL Converts a string representation of a value to a numeric expression.

Example

'Put the statement into the command buffer.
Result% = SqlCmd%(Sqlconn%, "SELECT id FROM sysobjects")

'Send the statement to SQL Server and start execution.
Result% = SqlExec%(Sqlconn%)

'Process the statement results.
Result% = SqlResults%(Sqlconn%)

'Retrieve and print the data in each row.
RowNum% = 0
DO UNTIL SqlNextRow%(Sqlconn%) = NOMOREROWS
   RowNum% = RowNum%  1
   PRINT "Row"; RowNum%;" object id is ";
   PRINT SqlData$(Sqlconn%, 1)
LOOP

See Also

SqlColLen%, SqlColName$, SqlColType%, SqlDatLen&, SqlNumCols%