Welcome to Dream.In.Code
Become a VB Expert!

Join 137,234 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,646 people online right now. Registration is fast and FREE... Join Now!




VB code on MySQL table

 
Reply to this topicStart new topic

VB code on MySQL table

dodzki2006
13 Feb, 2007 - 12:04 AM
Post #1

New D.I.C Head
*

Joined: 21 Sep, 2006
Posts: 30



Thanked: 1 times
My Contributions
34 days ago I posted a question on what is the VB code to know if a table is existing in MySQL, but I have not receive any reply. I hope that the following code will help the reader determine what is the problem after the "Do While Not .EOF" code.

Private Sub CheckTable()
Dim gcnDb As ADODB.Connection
Dim grsRs As ADODB.Recordset
Set gcnDb = New ADODB.Connection
Set grsRs = New ADODB.Recordset
DbNameMySQL = "mydata"
sTemp = "DATABASE=" & DbNameMySQL & ";"
With gcnDb
.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & ServerMySQL & ";" & sTemp & _
"USER=" & UserNameMySQL & ";" & _
"PASSWORD=" & PasswordMySQL & ";" & _
"PORT=" & PortMySQL & ";" & _
"OPTION=" & OptionMySQL & ";"
.CursorLocation = adUseClient
.Open
End With
Set grsRs = gcnDb.Execute("SHOW TABLES FROM " & DbNameMySQL)
With grsRs
If Not .RecordCount = 0 Then
.MoveFirst
Do While Not .EOF
If LCase(DbNameMySQL) = .Fields("TABLE").Value Then
MsgBox "Table already exist!"
Exit Do
End If
.MoveNext
Loop
End If
End With
grsRs.Close
Set grsRs = Nothing
gcnDb.Close
End Sub

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: VB Code On MySQL Table
13 Feb, 2007 - 05:20 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Are you experiencing a defined error? If so, can you please post it? Or does the code exhibit undesired behaviour? If so, can you please describe it?
User is online!Profile CardPM
+Quote Post

dodzki2006
RE: VB Code On MySQL Table
13 Feb, 2007 - 03:50 PM
Post #3

New D.I.C Head
*

Joined: 21 Sep, 2006
Posts: 30



Thanked: 1 times
My Contributions
I am sorry I failed to mention that DbNameMySQL and sTemp were declared as public variable strings in the module. MySQL does not forbid creating a table name with the same name as the database. In my code, I was testing if it can detect the presence of "mydata" table. The error returned is "Item can not be found in the collection corresponding to the requested name or ordinal" and it points to the " .Fields("TABLE").Value" clause as the culprit.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 04:00PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month