Jump to content

Insert into Oracle Table using ADO in AutoIt


Recommended Posts

Hi all,

I am breaking my head on this one. I don't know how to solve it.

I have an autoit script in which I submit information and need to enter new records into a database.

I have established a connection to the database and I know that it works because I have tested it against an SQL select statement.

Basically, I have to add new users to an Oracle users database, and I can select the last ID in that Users Table and I can display it on the screen. So therefore I know that I dont have a connection string problem.

I am using the following Insert SQL statement to try to insert a record in the table.

I tried with the following code:

With $adors

.ActiveConnection = $adodb

;.CursorLocation = "adUseClient"

;.LockType = "adLockReadOnly" ; Set ODBC connection read only

.Source = "Insert into Users Values(" & $newID & ", '"& $loginID & "', 0, '" & $fname & "', 'AM', '" & $lname & "', '" & $email & "');"

.Open

EndWith

with $adors being the result set and $adodb being the ADODB connection.

It didnt work.

I also tried that

$adors.AddNew

With $adors

.Fields("ID").Value = $newID

.Fields("Name").Value = $loginID

.Fields("Admin_Option").Value = 0

.Fields("First_Name").Value = $fname

.Fields("Domain").Value = "AM"

.Fields("Last_Name").Value = $lname

.Fields("Email").Value = $email

.Update

.Close

EndWith

And it did not work either.

Finally, I tried the following:

$sqlInsert = "Insert into Users Values(" & $newID & ", '"& $loginID & "', 0, '" & $fname & "', 'AM', '" & $lname & "', '" & $email & "');"

$adodb.Execute($sqlInsert);

which finally still did not work.

At this point, I have no clue what and how to do it.

Can anyone please guide me with that????

Thanks.

the123punch

Link to comment
Share on other sites

Add COM obj error handler to see detailed errors.

EDIT:

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

Func MyErrFunc()
    $hexnum=hex($objErr.number,8)

    Msgbox(0,"","We intercepted a COM Error!!"        & @CRLF                   & @CRLF & _
                 "err.description is: "    & $objErr.description    & @CRLF & _
                 "err.windescription is: " & $objErr.windescription & @CRLF & _
                 "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
                 "err.scriptline is: "     & $objErr.scriptline     & @CRLF & _
                 "err.number is: "         & $hexnum                 & @CRLF & _
                 "err.source is: "         & $objErr.source         & @CRLF & _
                 "err.helpfile is: "       & $objErr.helpfile       & @CRLF & _
                 "err.helpcontext is: "    & $objErr.helpcontext _
                )

    SetError(1)
EndFunc
Edited by Zedna
Link to comment
Share on other sites

Zedna,

Thanks a lot man, you saved me so much time. I tried implementing an error handling function previously so I can see what was happening but I was getting a run time error as soon as I execute my AutoIt script. Please see post : Error Handling in AutoIt.

So my error handling function before wasn't working and was causing my program to not run at all.

Now with yours it worked perfectly and I got to see errors and caught the error that was causing my insert statement not to run. It was the little semi-colin at the end of the statement that was causing the insert not to work. Now it is solved and the insert statement is working.

Thanks a lot!

Just anotehr question though.

With your error handler, other errors popped up which I don't really know how to interpret because they aren't causing me any problem.

Please find attached with this post a Word document with a print screen of the error messages I get before executing the Insert statement.

The first happens as soon as I start the executable program.

The second one happens after import user information from the Active Directory.

Would you know what it means???

Thank you so much.

the123punch

Errors.doc

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...