FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ejemplo de Tdatarow para crear Base de datos y tablas
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Wed Mar 15, 2017 01:44 PM

Buenos dias,

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

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Thu Mar 16, 2017 02:09 PM

Alguna sugerencia?

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 01:50 PM

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.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 01:54 PM

Thanks

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

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 02:13 PM

Which database you want to use with ADO?
MySql ? Or MSSql?

Regards



G. N. Rao.

Hyderabad, India
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 02:16 PM

MSSQl

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 04:29 PM
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Tue Mar 21, 2017 05:11 PM

Thanks so much

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Wed Mar 29, 2017 12:51 PM

Hello

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

Regards

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Thu Mar 30, 2017 01:32 PM

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 ?

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Thu Mar 30, 2017 01:39 PM
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Thu Mar 30, 2017 01:44 PM

Thanks a lot!

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Sat Apr 01, 2017 01:26 AM
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 (fw): Select all Collapse
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
Regards



G. N. Rao.

Hyderabad, India
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Sat Apr 01, 2017 12:36 PM

Thanks

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

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Ejemplo de Tdatarow para crear Base de datos y tablas
Posted: Sat Apr 01, 2017 03:12 PM

Not necessary

Regards



G. N. Rao.

Hyderabad, India