ilovecui Posted December 29, 2005 Posted December 29, 2005 (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 December 29, 2005 by ilovecui
sksbir Posted December 29, 2005 Posted December 29, 2005 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.
billmez Posted December 30, 2005 Posted December 30, 2005 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=11147You 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 errorMake 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.CloseEndFunc
ilovecui Posted December 30, 2005 Author Posted December 30, 2005 thanks,your answer is very useful and helpful for me !but i want to ask a more question?the question has written in the picturei want to read datas if the third row,like daterecord time second20051225 11 1220051226 12 2520051229 13 58 could you help me again?thanks!!i will continue to work hard,thanks for your help
billmez Posted December 30, 2005 Posted December 30, 2005 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 3msgbox(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.CloseEndFunc
ilovecui Posted January 1, 2006 Author Posted January 1, 2006 (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 January 1, 2006 by ilovecui
billmez Posted January 2, 2006 Posted January 2, 2006 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;300382Even though the syntax is a little different for AutoIt, the basic connection information should work fine.Happy new year.
ilovecui Posted January 2, 2006 Author Posted January 2, 2006 (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.840mdb password : 1but 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 reasonhappy new year to you! thanks for your help again!when i'm in trouble,i always see the light--your helpthanksand happy new year to everyone heredb_test.rar Edited January 2, 2006 by ilovecui
billmez Posted January 2, 2006 Posted January 2, 2006 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now