Jump to content

Database


 Share

Recommended Posts

I use a Program called "All My Movies." This program is a convenient way to organize my movie titles.

I can open the database file in Microsoft Access. I want to be able to add a movie title to the column titled "originalMovie" on the table "Movies".

I know how to have autoit open the file and enter the correct keys, but i would like to write something like "filewriteline('C:\My Documents\moviename.txt',1)" only for a Database.

Any Ideas? Examples?

Link to comment
Share on other sites

I want to be able to add a movie title to the column titled "originalMovie" on the table "Movies".

In order todo this you will need to connect to the access database and use a insert sql to add a movie title.

I know how to have autoit open the file and enter the correct keys, but i would like to write something like "filewriteline('C:\My Documents\moviename.txt',1)" only for a Database.

I have no clue what you mean by this? First you are talking about writing to a database and here you are talking about some text file.
Link to comment
Share on other sites

"In order todo this you will need to connect to the access database and use a insert sql to add a movie title."

Do you have an example of what this would look like?

"I have no clue what you mean by this? First you are talking about writing to a database and here you are talking about some text file."

This was an example. I would like to know what code i would need for filling in the 'xxxxx' in.... 'FileWriteLine' is to '.txt' as 'xxxxx' is to ".mdb"

hope that clarifies

Link to comment
Share on other sites

"In order todo this you will need to connect to the access database and use a insert sql to add a movie title."

Do you have an example of what this would look like?

"I have no clue what you mean by this? First you are talking about writing to a database and here you are talking about some text file."

This was an example. I would like to know what code i would need for filling in the 'xxxxx' in.... 'FileWriteLine' is to '.txt' as 'xxxxx' is to ".mdb"

hope that clarifies

GEOSoft has a set of functions worked up for deaing with Access databases in his Access UDF here: http://www.autoitscript.com/forum/index.php?showtopic=40397
Link to comment
Share on other sites

;what am i doing wrong? this does not alter my database in any way.

$adSource = "K:\My Movies\TempMyMovies.mdb" ;this is the name and location of my database

$adTable = "movies" ;this is the table name

$rData = "testMovieName" ;this is the text to be added

$adCol = "Name" ;this is the column name

#include-once

Global Const $adoProvider = 'Microsoft.Jet.OLEDB.4.0; '

Global Const $adOpenDynamic = 2

Global Const $adOpenStatic = 3

Global Const $adLockReadOnly =1

Global Const $adLockPessimistic = 2

Global Const $adLockOptimistic = 3

Global Const $adLockBatchOptimistic = 4

Global Const $adPersistXML = 1

Global Const $adUseClient = 3

Global Const $adSchemaTables = 20

Global Const $adVarChar = 200

Global Const $MaxCharacters = 255

;Private Functions

Func _accessOpen($adSource)

$oADO = ObjCreate("ADODB.Connection")

$oADO.Provider = $adoProvider

$oADO.Open ($adSource)

Return $oADO

EndFunc ;<===> _accessOpen()

Func _accessOpenRecordset()

$oRec = ObjCreate("ADODB.Recordset")

Return $oRec

EndFunc ;<===> _accessOpenRecordset()

;===============================================================================

; Function Name: _accessAddRecord()

; Description: Add a new record (single or multiple fields) in an existing MS Access database table

; Syntax: _accessAddRecord($adSource, $adTable)

; Parameter(s): $adSource - The full path/filename of the database to be opened

; $adTable - the name of the table to add the record to

; $rData - Data to be added to field (to add data to multiple fields this must be an array) see notes

; $adCol - the name or 0 based index of the field to add the data to when $rData is not an array (default is first field)

; Requirement(s):

; Return Value(s): Success - @Error = 0 and record is added to table

; Failure - Sets @Error

; 1 = unable to create connection

; 2 = unable to create recordset

; Author(s): GEOSoft

; Note(s):

; Modification(s):

;===============================================================================

Func _accessAddRecord($adSource, $adTable, $rData,$adCol = 0)

If NOT IsArray($rData) Then

$rData = StringSplit($rData,'|')

EndIf

$oADO = 'ADODB.Connection'

If IsObj($oADO) Then

$oADO = ObjGet('',$oADO)

Else

$oADO = _accessOpen($adSource)

EndIf

If IsObj($oADO) = 0 Then Return SetError(1)

If Not IsObj($oADO) Then Return SetError(2, 0, 0)

$oRec = _accessOpenRecordset();ObjCreate("ADODB.Recordset")

If IsObj($oRec) = 0 Then Return SetError(2)

With $oRec

.Open ("SELECT * FROM " & $adTable , $oADO, $adOpenStatic, $adLockOptimistic)

.AddNew

If IsArray($rData) Then

For $I = 1 To Ubound($rData) -1;$rData[0]

$rData[$I] = StringStripWs($rData[$I],1)

.Fields.Item($I -1) = $rData[$I]

Next

Else

.Fields.Item($adCol) = $rData

EndIf

.Update

.Close

EndWith

$oADO.Close()

EndFunc ;<===> _accessAddRecord()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...