Sign in to follow this  
Followers 0
ilovecui

How to read datas like this in the MDB?

9 posts in this topic

#1 ·  Posted (edited)

How to read datas like this in the MDB?

Func _SelectData($dbname, $tblname, $fldname, $T)

$addfld = ObjCreate("ADODB.Connection")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)

$RS =ObjCreate("ADODB.Recordset")

$RS.ActiveConnection = $addfld

$RS.Open ("Select "&$T & " From " & $tblname )

msgbox(0,"",$RS.Fields(0).Name)

msgbox(0,"",$RS.Fields(0).Value)

$addfld.Close

EndFunc

i ever used this script to read it,but i couldn't read datas like this: the pictute in the Attached thumbnail(s)

i want to use it to read "daterecord" ---"20051226" ----"time"---"12" , "daterecord" ---"20051226" ----"second"---"25" and "daterecord" ---"20051229" ----"second"---"58",but.......failed

cuold you help me to solve this problem???thanks

Edited by ilovecui

Share this post


Link to post
Share on other sites



How to read datas like this in the MDB?

Hello,

autoit is not object oriented. so you cannot use object like ADODB.connection.

I suggest you to call your vbs script from autoit program.

Share this post


Link to post
Share on other sites

Here is a link to a post containing code to connect to SQL using ADO and the AutoIt beta. You should be able to see the problems in your code from this post.

http://www.autoitscript.com/forum/index.php?showtopic=11147

You don't really say what happens when you try to run your code and that would be helpful to point you in the right direction. A question like this really belongs in the v3support forum where you will probably get more help.

A couple things I see right offhand:

$fldname is not used in the function so I got a badly formed function error

Make sure you use the full path to the database and it is not password protected or else you will need to add login info into the connection open statement.

The code below works and will return a message box with the name and value of the first 3 fields of the first record. To return more records you will need to iterate through the recordset using while not $RS.EOF.

Hope this helps,

Bill

_SelectData()

Func _SelectData($dbname = "C:\FullPathToDatabase.mdb", $tblname = "MyTable", $T = "*")

$addfld = ObjCreate("ADODB.Connection")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)

$RS =ObjCreate("ADODB.Recordset")

$RS.ActiveConnection = $addfld

$RS.Open ("Select " & $T & " From " & $tblname )

msgbox(0,"", "Name: " & $RS.Fields(0).Name & " - Value: " & $RS.Fields(0).Value & @CRLF & "Name: " & $RS.Fields(1).Name & " - Value: " & $RS.Fields(1).Value & @CRLF & "Name: " & $RS.Fields(2).Name & " - Value: " & $RS.Fields(2).Value)

$RS.Close

$addfld.Close

EndFunc

Share this post


Link to post
Share on other sites

thanks,your answer is very useful and helpful for me !

but i want to ask a more question?

the question has written in the picture

i want to read datas if the third row,like

daterecord time second

20051225 11 12

20051226 12 25

20051229 13 58

could you help me again?

thanks!!

i will continue to work hard,thanks for your help

Share this post


Link to post
Share on other sites

See the changes in the code below and comments

_SelectData()

Func _SelectData($dbname = "C:\FullPathToDatabase.mdb", $tblname = "MyTable", $T = "*")

$addfld = ObjCreate("ADODB.Connection")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)

$RS =ObjCreate("ADODB.Recordset")

$RS.CursorType = 3 ; set client side cursor to return count

$RS.ActiveConnection = $addfld

$RS.Open ("Select " & $T & " From " & $tblname )

$RS.Move(2) ; Recordset objects start at 0, so 2 is the 3rd record

; If you want to see the first 3 records, comment out the $RS.Move line above and uncomment the

Lines below. You will see a new record with each click of OK until it exits after the 3rd record

;While not $RS.EOF

; For $i = 1 To 3

msgbox(0,"", "Name: " & $RS.Fields(0).Name & " - Value: " & $RS.Fields(0).Value & @CRLF & "Name: " & $RS.Fields(1).Name & " - Value: " & $RS.Fields(1).Value & @CRLF & "Name: " & $RS.Fields(2).Name & " - Value: " & $RS.Fields(2).Value)

;$RS.MoveNext

;Next

;ExitLoop

;WEnd

$RS.Close

$addfld.Close

EndFunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

oh!!thanks for your help again.It's very useful for me with your script!

if the mdb with password,how could i rewrite the sataments in the script?

is this right ?

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Password=123;Data Source=" & $dbname)

but it could't pass in autoit?? would you please tell me where the problem comes from?

thanks again!

Edited by ilovecui

Share this post


Link to post
Share on other sites

Try This:

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname & "; UID=username; PWD=password")

Here is a link to MS database connection strings:

http://support.microsoft.com/default.aspx?...kb;en-us;300382

Even though the syntax is a little different for AutoIt, the basic connection information should work fine.

Happy new year.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

thanks !

i try to rewrite the script,but..erro like this:

: ==> The requested action with this object has failed.:

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname & "; UID=; PWD=1")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname & "; UID=; PWD=1")^ ERROR

>AutoIT3.exe ended.

>Exit code: 0 Time: 2.840

mdb password : 1

but UID ??? is it my computer name??login name???

here is my test documents,maybe i question my ability . i try to fill the computer name or not to fill it,but the erro comes out with the same reason

happy new year to you! thanks for your help again!

when i'm in trouble,i always see the light--your help

thanks

and happy new year to everyone here

db_test.rar

Edited by ilovecui

Share this post


Link to post
Share on other sites

UID stands for user ID and would be the user login for the database. In SQL server the system user is SA by default. I don't know about Access as I believe it is on an individual database level.

You might also try setting the password to something other than 1 which might be taken as true, or try enclosing it in a single quote '1'.

Perhaps if you try a search on MSDN (you can get there from the link I sent the other day) for something about access password, you can find an answer.

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