Page 1 of 1 1
Topic Options
#110120 - 2003-12-11 07:22 PM MODIFY ACCES DATABASE
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
Hi, how I do to modify one file.mdb (access 97) whit kixtart?
_________________________
Look always 4 the best...

Top
#110121 - 2003-12-11 07:31 PM Re: MODIFY ACCES DATABASE
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
You should search the forum first. There are lots of posts and UDFs on how to do database functions.
Top
#110122 - 2003-12-11 07:55 PM Re: MODIFY ACCES DATABASE
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See for example DBCOMMAND() in the UDF Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
#110123 - 2003-12-11 08:06 PM Re: MODIFY ACCES DATABASE
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
I use

this script
Code:
 

$dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\journal.mdb'
$sql="INSERT INTO PARAMETROS VALUES('eee','fff')"
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR
$sql="SELECT Field1, Field2 FROM Table1"
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR
For $row=0 to Ubound($recordset,1)
For $column=0 to Ubound($recordset,2)
? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
Next
Next


Function DBCommand($ConnDSN,$sql)
Dim $objConn, $adStateOpen
Dim $Conntimeout, $CmdTimeout
Dim $cmdCommand, $rsRecordset
Dim $Records, $FinalRecords
Dim $adCmdText, $adLockReadOnly, $adOpenStatic
Dim $row, $rows, $column, $columns

$ConnDSN=Trim($ConnDSN)
If NOT $ConnDSN
Exit 87
EndIf
$sql=Trim($sql)
If NOT $sql
Exit 87
EndIf

; default database parameters
$adStateOpen=1
$ConnTimeout=15
$CmdTimeout=30
$adCmdText = 1
$adOpenStatic = 3
$adLockReadOnly = 1

; open the database connection
$objConn = CreateObject("ADODB.Connection")
If @ERROR
Exit @ERROR
EndIf
$objConn.ConnectionTimeout = $ConnTimeout
If @ERROR
Exit @ERROR
EndIf
$objConn.CommandTimeout = $CmdTimeout
If @ERROR
Exit @ERROR
EndIf
$objConn.Open($ConnDSN)
If @ERROR
Exit @ERROR
EndIf
If NOT $objConn.State=$adStateOpen
$objConn=''
$DBCommand=''
Exit @ERROR
EndIf

; create the database command object
$cmdCommand = CreateObject('ADODB.Command')
If @ERROR
Exit @ERROR
EndIf
$cmdCommand.ActiveConnection = $objConn
If @ERROR
Exit @ERROR
EndIf
$cmdCommand.CommandType = $adCmdText
If @ERROR
Exit @ERROR
EndIf
$cmdCommand.CommandText = $sql
If @ERROR
$DBCommand=@ERROR
Exit @ERROR
EndIf

If InStr($sql,'SELECT')=1
; create the recordset object
$rsRecordSet = CreateObject('ADODB.Recordset')
If @ERROR
Exit @ERROR
EndIf
$rsRecordset.CursorType = $adOpenStatic
If @ERROR
Exit @ERROR
EndIf
$rsRecordset.LockType = $adLockReadOnly
If @ERROR
Exit @ERROR
EndIf
$rsRecordset.Open($cmdCommand)
If @ERROR
Exit @ERROR
EndIf

If $rsRecordset.EOF AND $rsRecordSet.BOF
; recordset is empty
$FinalRecords=''
Else
If @ERROR
Exit @ERROR
EndIf

; retrieve all records at once and transpose into tabular format
$Records = $rsRecordset.GetRows()
$columns=Ubound($records,1)
$rows=Ubound($records,2)
ReDim $FinalRecords[$rows,$columns]
For $row=0 to $rows
For $column=0 to $columns
$FinalRecords[$row,$column]=$records[$column,$row]
Next
Next
EndIf

; close recordset
If $rsRecordset.state=$adStateOpen
$rsRecordset.Close()
If @ERROR
Exit @ERROR
EndIf
EndIf

$rsRecordset=''
$cmdCommand=''

$DBCommand=$FinalRecords
Else
$rsRecordset=$cmdCommand.Execute()
$cmdCommand=''
$rsRecordset=''
If @ERROR
Exit @ERROR
EndIf

$DBCommand=0
EndIf

; close the database connection
If $objConn.State = $adStateOpen
$objConn.Close()
If @ERROR
Exit @ERROR
EndIf
EndIf
$objConn=''

Exit 0
EndFunction



and return



Error = -2147352567 - COM exception error "Open" (Microsoft OLE DB Provider for
ODBC Drivers - [Microsoft][Administrador de controladores ODBC] El nombre del or
igen de datos no se encontró y no se especificó ningún controlador predeterminad
o) [-2147352567/80020009]
Error = -2147352567 - COM exception error "Open" (Microsoft OLE DB Provider for
ODBC Drivers - [Microsoft][Administrador de controladores ODBC] El nombre del or
igen de datos no se encontró y no se especificó ningún controlador predeterminad
o) [-2147352567/80020009]
C:\>


_________________________
Look always 4 the best...

Top
#110124 - 2003-12-11 08:10 PM Re: MODIFY ACCES DATABASE
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Are the database drivers installed correctly? Does the database contain a table "Table1" with two fields "Field1" and "Field2"? Does it contain a table "PARAMETROS"? Are the fieldtypes correct?
_________________________
There are two types of vessels, submarines and targets.

Top
#110125 - 2003-12-11 08:20 PM Re: MODIFY ACCES DATABASE
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia

I´m sorry seal, I don´t read the full code, I comment the second part but return


Error = -2147352567 - COM exception error "Open" (Microsoft OLE DB Provider for
ODBC Drivers - [Microsoft][Administrador de controladores ODBC] El nombre del or
igen de datos no se encontró y no se especificó ningún controlador predeterminad
o) [-2147352567/80020009]
C:\>

How I know If have the drivers correct?
My pc don´t have microsft access program.
And I can't install it.


I write

$dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\journal.mdb'
$sql="INSERT INTO PARAMETROS VALUES('eee','fff')"
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR

;$sql="SELECT Field1, Field2 FROM PARAMETROS"
;$recordset = DBCommand($dsn,$sql)
;? 'Error = '+@ERROR+' - '+@SERROR
;For $row=0 to Ubound($recordset,1)
; For $column=0 to Ubound($recordset,2)
; ? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
; Next
;Next

func.....

_________________________
Look always 4 the best...

Top
#110126 - 2003-12-11 08:36 PM Re: MODIFY ACCES DATABASE
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
MS Access Database Drivers are installed e.g. via MDAC, see http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28001860 and http://www.webwizguide.info/asp/faq/ODBC_drivers.asp

You need MS Access to create the inital Access database. Where's journal.mdb coming from?

You will also need to make sure that you have the correct tables and fields inside the tables.
_________________________
There are two types of vessels, submarines and targets.

Top
#110127 - 2003-12-11 10:01 PM Re: MODIFY ACCES DATABASE
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
Hi, seal, I download de mdac 2.8 and install and don´t work, then download 2.1 and work, now the driver work fine.
The table is parametros
I need change 2 fields
fehca_sistema and fecha_efectiva
whit a text for ex: 20031203

how i do whit that udf?
_________________________
Look always 4 the best...

Top
#110128 - 2003-12-11 10:08 PM Re: MODIFY ACCES DATABASE
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You will need to craft appropriate SQL statements, e.g. UPDATE TABLE parametros SET fehca_sistema="aaa", fecha_efectiva='bbb' WHERE fecha_efectiva='ccc' would update the specific record. with the new values. You might want to read a SQL tutorial first.
_________________________
There are two types of vessels, submarines and targets.

Top
#110129 - 2003-12-11 10:13 PM Re: MODIFY ACCES DATABASE
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
tks

Break on
? "indique fecha"
Gets $x
$dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\journal.mdb'
$sql="update parametros set fecha_sistema="+$x+", fecha_efectiva="+$x
?$sql
Get $x
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR


work now.
_________________________
Look always 4 the best...

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.058 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org