Sign in to follow this  
Followers 0
Hannes

Autoit Beta 3.1.1.114 And Ado Recordset

10 posts in this topic

Hello,

i need/want to use ado recordsets instead of arrays, because sorting and querying is much better than handling arrays.

I take the code from my vbscript, where there was everthing fine...

When i run the script it generates a error message:

--Error: The requested action with this object has failed.--

this line causes the error

...

$objADOR.Fields.Append "Filed1", $adVarChar, $adMaximize

...

(This is some of my script, the rest of the code is fully functional)

; need ador for recording values

Global const $adVarChar = 200

Global const $adMaximize = 255

; needed for creating indexes

Global const $adUseClient = 3

Global $objADOR

$objADOR = ObjCreate("ADODB.Recordset")

$objADOR.CursorLocation = $adUseClient (up to this line, no erros)

$objADOR.Fields.Append "Filed1", $adVarChar, $adMaximize

$objADOR.Fields.Append "Filed2", $adVarChar, $adMaximize

$objADOR.Fields.Append "Filed3", $adVarChar, $adMaximize

$objADOR.Fields.Append "Field4", $adVarChar, $adMaximize

$objADOR.Fields.Append "Field5", $adVarChar, $adMaximize

if @error then msgbox(0,"Error","Code " & @error & " in Line "& @ScriptLineNumber)

$objADOR.Open

Can anyone help ?!

Thanks.

Share this post


Link to post
Share on other sites



Hello,

i need/want to use ado recordsets instead of arrays, because sorting and querying is much better than handling arrays.

I take the code from my vbscript, where there was everthing fine...

When i run the script it generates a error message:

--Error: The requested action with this object has failed.--

this line causes the error

...

$objADOR.Fields.Append "Filed1", $adVarChar, $adMaximize

...

(This is some of my script, the rest of the code is fully functional)

; need ador for recording values

Global const $adVarChar = 200

Global const $adMaximize = 255

; needed for creating indexes

Global const $adUseClient = 3

Global $objADOR

$objADOR = ObjCreate("ADODB.Recordset")

$objADOR.CursorLocation = $adUseClient (up to this line, no erros)

$objADOR.Fields.Append "Filed1", $adVarChar, $adMaximize

$objADOR.Fields.Append "Filed2", $adVarChar, $adMaximize

$objADOR.Fields.Append "Filed3", $adVarChar, $adMaximize

$objADOR.Fields.Append "Field4", $adVarChar, $adMaximize

$objADOR.Fields.Append "Field5", $adVarChar, $adMaximize

if @error then msgbox(0,"Error","Code " & @error & " in Line "& @ScriptLineNumber)

$objADOR.Open

Can anyone help ?!

Thanks.

What is it that you are trying to do, add new columns to the table?

Share this post


Link to post
Share on other sites

You need parentheses around your commands, like so

$objADOR.Fields.Append ("Field5", $adVarChar, $adMaximize)

Try that. Or if you're using MySQL look at the link to the UDF's in my sig.

~cdkid


AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

What is it that you are trying to do, add new columns to the table?

Yes,

at that moment, when the script attempts to append the first field to the recordset, an errror occure.

I tried to change the syntax, but no change in behavior...

$objADOR = ObjCreate("ADODB.Recordset")

$objADOR.Fields.Append "FieldName", $adVarChar, $adMaximize

In VBScript you use this command (objAdor.Fields.Append "Name", %kindofChars%, %MaxNrOfChars%)

to define fieldnames in a filedset.

Share this post


Link to post
Share on other sites

You need parentheses around your commands, like so

$objADOR.Fields.Append ("Field5", $adVarChar, $adMaximize)

Try that. Or if you're using MySQL look at the link to the UDF's in my sig.

~cdkid

Thanks a lot.

This was the prob.

I hope this will take a notice in the helpfile and the udf's with the final version.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you look at the "OBJ/COM reference" section in the help file they all have parentheses for any methods being executed. And the reason you can do it in VBScript is because you're calling a non-returning function (sub), thus it returns an error when you do use one. In AutoIt almost all functions require parentheses.

~cdkid

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

Yes,

at that moment, when the script attempts to append the first field to the recordset, an errror occure.

I tried to change the syntax, but no change in behavior...

$objADOR = ObjCreate("ADODB.Recordset")

$objADOR.Fields.Append "FieldName", $adVarChar, $adMaximize

In VBScript you use this command (objAdor.Fields.Append "Name", %kindofChars%, %MaxNrOfChars%)

to define fieldnames in a filedset.

You don't need a recordset to append fields to a table.

You can use:

$AlterSQL = "ALTER TABLE " & $TableName & " "
$AlterSQL &= "[FIELD1] varchar (50) NULL, " 
$AlterSQL &= "[FIELD2] varchar (50) NULL, " 
$AlterSQL &= "[FIELD3] varchar (30) NULL; " 

$ConnObj.execute($AlterSQL)

Obviously use your open connection object and the desired table name.

Share this post


Link to post
Share on other sites

Sometimes ADO(DB) cuts off queries after X number of characters, so it is probably best to use ADO Recordsets.

~cdkid


AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

Sometimes ADO(DB) cuts off queries after X number of characters, so it is probably best to use ADO Recordsets.

~cdkid

Not a problem I've ever had with SQL server or Access. I'd imagine that somewhere there is a point where that would be the case, but I do a lot of web based db development and have never experienced it.

It is also more efficient to use a table direct query than opening a recordset.

Thanks

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You don't need a recordset to append fields to a table.

You can use:

$AlterSQL = "ALTER TABLE " & $TableName & " "
$AlterSQL &= "[FIELD1] varchar (50) NULL, " 
$AlterSQL &= "[FIELD2] varchar (50) NULL, " 
$AlterSQL &= "[FIELD3] varchar (30) NULL; " 

$ConnObj.execute($AlterSQL)

Obviously use your open connection object and the desired table name.

Please understand, i am using an ado recordset to get infos into ram, this is not a table like an sql table or something else...

ADO Recordsets in vbscript don't understand real sql statements, you have to use the syntax for ador (see msdn or mdac sdk from MS).

My next prob is, when i try to set a fieldname with a value, i only know how to use it like in vbscript, but in autoit i have to set () elsewhere, but i don't exactly where:

i tried this, but got an error:

$objADOR.AddNew

$objADOR("Vendor") = $strValue ' this would be the same as vbscript

<--and this

$objADOR.AddNew("Vendor" = $strVendor)

-->

$objADOR.Update

(in vbscript i used that code without any problems)

objADOR.AddNew

objADOR("FieldName1") = strValue1

objADOR("FieldName2") = strValue2

objADOR.Update

----------------

Ok, now i understand a little bit more.

I read the ms sdk and where was the right syntax, i was searching for (although in vbscript it was right, in autoit you need the correct syntax):

$objADOR.AddNew("FieldName1",$strValue)

$objADOR.Update

Edited by Hannes

Share this post


Link to post
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
Sign in to follow this  
Followers 0