nageswaragunupudi wrote:This example shows
1. Connect to MS Sql server
2. Create a new Database (Catalog) by name FWH
3. Export c:\fwh\samples\customer.dbf to the Server in the Catalog (database) FWH
4. Open CUSTOMER table and browse.
- Code: Select all Expand view
#include "fivewin.ch"
#include "adofuncs.ch"
//----------------------------------------------------------------------------//
function Main()
local oCn, oRs
//----------------------------------------------------------------------------//
// Check if Database cInitCat exists on the server
// and create if does not exist
//----------------------------------------------------------------------------//
? "Connect to Server"
oCn := FW_OpenAdoConnection( "MSSQL,SQLEXPRESS,,SA,Secret", .t. )
if oCn == nil
? "Connect Fail"
QUIT
endif
? "Check and create database " + cInitCat + " if needed"
oRs := oCn:OpenSchema( 1, cInitCat )
if oRs == nil
? "Error"
QUIT
endif
if oRs:RecordCount() > 0
? "DataBase " + cInitCat + "Exists"
else
oCn:Execute( "CREATE DATABASE " + cInitCat )
? "Database " + cInitCat + " Created"
endif
oRs:Close()
oCn:Close()
//----------------------------------------------------------------------------//
// Connect to the sever / Database, Export Data and Browse exported data
//----------------------------------------------------------------------------//
? "Connect to Server Database " + cInitCat
oCn := FW_OpenAdoConnection( "MSSQL,SQLEXPRESS,FWH,SA,Secret", .t. )
if oCn == nil
? "Connect Fail"
QUIT
endif
? "Importing Customer.dbf"
FW_AdoImportFromDBF( oCn, "c:\fwh\samples\customer.dbf", "CUSTOMER" )
? "Imported. Opening CUSTOMER table on the MSSQL server"
oRs := FW_OpenRecordSet( oCn, "CUSTOMER" )
XBROWSER oRs
oRs:Close()
oCn:Close()
? "Done"
return nil
In the function FW_OpenAdoConnection:
Please replace
SQLEXPRES with your Server name
FWH with the Database name you want
Secret with your password
Next release of FWH includes TRecSet class.
This will be fully compatible with ADO syntax and also TData/TDatabase syntax.
Existing applications will run without any change. Just replace
oRs := TOleAuto():New( "ADODB.RecordSet" )
with
oRs := TRecSet():New()
Advantages are :
a) We can use oRs:Fields( "HireDate" ):Value or oRs:HireDate
b) We need not check if record set is empty before using MoveFirst(), etc.
We can safely use MoveFirst() or GoTop() etc everywhere. Error checking is builtin
c) Field Access and Assign provide for padding/trimming/null values/ and other necessary conversions and error checking. Also takes care of differences between different databases.
Hi,
Is this code valid for MySQL?
Thanks