Page 1 of 2

Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Wed Mar 15, 2017 1:44 pm
by Compuin
Buenos dias,

Alguien tendra un ejemplo de como crear base de datos y tablas con la Tdatarow?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Thu Mar 16, 2017 2:09 pm
by Compuin
Alguna sugerencia?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 1:50 pm
by nageswaragunupudi
The purpose of TDataRow is not for creating database or tables.
The class is used to read one row from a table of any kind of database for editing and saving.

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 1:54 pm
by Compuin
Thanks

Which class is used to create Database and tables using ADO?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 2:13 pm
by nageswaragunupudi
Which database you want to use with ADO?
MySql ? Or MSSql?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 2:16 pm
by Compuin
MSSQl

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 4:29 pm
by nageswaragunupudi
First thing is to connect to the server. The server can be a remote server or SQLEXPRESS on local PC.
Please use this function to connect to the server. MSSQL Server/SQLEXPRESS can be configured
to accept logins as user/password or with Windows authentication or both. When configuring it is desirable to allow user/password based logins. For MSSQL server, built-in adiminstrator account's name is SA, like "root" for MySql.

Syntax:
oCn := FW_OpenAdoConnection( { "MSSQL", cServer, [cDataBase], cUser, cPassword }, lShowError )
OR
oCn := FW_OpenAdoConnection( { "MSSQL,cServer,[cDataBase],cUser,cPassword", lShowError )

When we are connecting for the first time we can ommit database name because we want to create a database after logging in.

Example:
Code: Select all  Expand view

oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS",,"SA","secret" }, .t. )
if oCn == nil
   ? "Connect Fail"
   return nil
endif

// proceed using the connection.
// Create a database named FWH

oCn:Execute( "CREATE DATABASE FWH" )
oCn:Close()
 


Now we can loging with the database name and start creating tables.
In this example, we copy a dbf file to the server to the database FWH, open the table and browse it
Code: Select all  Expand view

oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS","FWH","SA","secret" }, .t. )
if oCn == nil
   ? "Connect Fail"
   return nil
endif

FW_AdoImportFromDBF( oCn, "c:\fwh\samples\customer.dbf" )

oRs  := FW_OpenRecordSet( oCn, "customer" )
XBROWSER oRs FASTEDIT
oRs:Close()
oCn:Close()
 


We can continue with more examples depending on your requirements.

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Tue Mar 21, 2017 5:11 pm
by Compuin
Thanks so much

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Wed Mar 29, 2017 12:51 pm
by Compuin
Hello

It is possible to create a wrapper function instead to write Fw_OpenAdoConnection to call it ? Some sample?

Regards

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Thu Mar 30, 2017 1:32 pm
by Compuin
This example is good but it just create Tables from DBF.

Another example to create it from code? The same for Database creation using CREATE DATABASE ?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Thu Mar 30, 2017 1:39 pm
by cnavarro

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Thu Mar 30, 2017 1:44 pm
by Compuin
Thanks a lot!

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Sat Apr 01, 2017 1:26 am
by nageswaragunupudi
It is possible to create a wrapper function instead to write Fw_OpenAdoConnection to call it ?

FW_OpenAdoConnection() is itself a wrapper function. Using this function resolves many issues relating to construction of connection strings yourself.

Creating Database

oCn:Execute( "CREATE DATABASE <databasename>" )

Creating Table:
FWH provides easy and simpler function to create tables. You can use the same function create the same table in different RDBMs ( eg Access, MSSQL, MySql, Oracle ). Also FWH function works on those RDBMs which do not fully support ADOX.

FWAdoCreateTable( cTable, aStruct, oCn ) // aStruct is identical to DBSTRUCT()

Usage:
Code: Select all  Expand view

FWAdoCreateTable( "sales", { { BILLNO, 'N', 5, 0 }, ;
                                            { "DETAIL", "C", 20, 0 }, ;
                                            { "QTY", "N", 5, 0 }, ;
                                            { "RATE", "N", 5, 2 }, ;
                                            { "AMOUNT", "N", 12,2 } }, oCn )
 

Faster than using ADOX
Works with all RDBMSs even where ADOX is not supported or not fully supported.
Same syntax works for different RDBMSs, thereby enabling portable programming accross different RDBMSs

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Sat Apr 01, 2017 12:36 pm
by Compuin
Thanks

In order to work with Ado with MSSQL...should I install some specific driver?

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

PostPosted: Sat Apr 01, 2017 3:12 pm
by nageswaragunupudi
Not necessary