• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

GetString method (ADO)

Started by Eddy Larsson, February 08, 2009, 08:26:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Eddy Larsson

Hi Jose

Thanx for very good site. Maybe you can help me with this.

When I build html pages and extract data from databases i use the GetString method (ADO). I want to
specify my own delimeters between columns.

I use the example EX_ADO_GetString.BAS

Here is part of the code

SqlStr = "SELECT TOP 1 * FROM Publishers"
 

'Get the recordset as an string
      LOCAL NBSPACE AS STRING
            NBSPACE = CHR$(160)
      strText = pRecordset.GetString(%adClipString,-1,"</TD><TD>","</TD></TR><TR><TD >",NBSPACE)

I got the result:

1????ACM????Association for Computing Machinery????11 W. 42nd St., 3rd flr.????New York????NY????10036????212-869-7440????????????????/

When I Use old syntax and old wrappers with pbcc4 it works.

I don't know what I doing wrong.

Regards
Eddy Larsson

Gérôme Guillemin

Hello,

The GetString method can have its 2 first parameters as missing params, the 3rd one is a string one aka the kind of seperator.
In FBSL we can type :

#uses "@|WIN32"
' --------------------------------------------------------------
'// ADODB CSV builder for MSACCESS MDB using GetString method
'// Author : Gerome GUILLEMIN
'// Methods exposed :
'// GetValue, PutValue, CallMethod, PutRef
'// CreateObject, GetObject, ReleaseObject
'// String = recordset.GetString([StringFormat], [NumRows], [ColumnDelimiter], [RowDelimiter], [NullExpr])
'// Parameter       Description
'// StringFormat    Currently the only supported format is AdClipString, which returns a row and column delimited string
'// NumRows         The number of rows to be returned
'// ColumnDelimiter The character inserted between columns. The default is a Tab character
'// RowDelimiter    The character inserted between rows. The default is a Carriage Return character.
'// NullExpr        Expression to be used in place of a Null value. The default is an empty string
' --------------------------------------------------------------
#Option Strict
#AppType CONSOLE

'// Declare variables : be aware of 'DRIVER'
Const CnStr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=.\mydb.mdb"
Dim %dbi, %dbq, $query, $csvFile, %fp, $szBuffer, %iCount, %j

'// Setting Object variables
Set dbi = CreateObject( "ADODB.Connection", "" )
Set dbq = CreateObject( "ADODB.RecordSet", "" )

'// Open connection
PutValue( dbi, ".ConnectionString = %s", CnStr )
CallMethod( dbi, ".Open %s", CnStr )

'// Query the records and display them
query = "Select * from Table1"
CallMethod( dbi, ".Execute %s", query )
CallMethod( dbq, ".Open %s, %o", query, dbi )

'// GetString method
fp = FileOpen( "Out_request1.csv", BINARY_NEW )
    CallMethod( dbq, ".MoveFirst" )
    FilePut( fp, GetValue( "%s", dbq, ".GetString %m, %m, %s, %m, %m", ";" ) )
FileClose( fp )

CallMethod( dbq, ".Close" )

'// close the connection
CallMethod( dbi, ".Close" )

ReleaseObject( dbi )
ReleaseObject( dbq )

Pause


%m == missing aka optioanl parameter.
Hope this can help you

José Roca

#2
Quote
I don't know what I doing wrong.

The wrappers did the unicode conversion for you.

Use:


strText = pRecordset.GetString(%adClipString, -1, UCODE$("</TD><TD>"), UCODE$("</TD></TR><TR><TD >"), UCODE$(NBSPACE))


Eddy Larsson