求救!VB连接远程MYSQL出错!请大侠们不吝赐教!
这个源码是连接到我的网站(网上买的空间)的mysql数据库的,我用的DataGrid1控件连接Adodc1控件,能够读出表的名称了,但是,表的内容还是没有显示出来,提示如下:
[MySQL][ODBC 3.15 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax: check the manual that corresponds to your MYSQL server version for the right syntax to use near '[destoon_404]' at line 1
点击确定后,又提示如下:
对象'Refresh'的方法'IAdodc'失败
各位大侠不吝赐教,帮帮忙!看看是怎么回事!
这个是我的源码,源码如下:
Private Sub Form_Load()
Combo1.Clear
GetTable
End Sub
Private Sub Combo1_Click()
'选择表
On Error GoTo ErrorHandler
adoSQL.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; " _
& " Password=" & txtPassword & "; " _
& " Persist Security Info=False; " _
& " User ID=" & txtUser & "; " _
& " Server=" & txtServer & ";" _
& " DataBase=" & txtDatabase & "; " _
& " OPTION=3"
adoSQL.RecordSource = "SELECT * FROM [" & cboTables.Text & "]"
adoSQL.Refresh
FillcboFields
Exit Sub
ErrorHandler:
MsgBox Error$
End Sub
Private Sub GetTable()
Dim X As Integer
Dim CurTable As String
Set CTN = New ADODB.Connection
Set RSTable = New ADODB.Recordset
'打开连接
CTN.ConnectionString = ConSTR
CTN.Open
Set RSTable = CTN.OpenSchema(adSchemaTables)
RSTable.MoveFirst
Do Until RSTable.EOF
If RSTable.Fields("TABLE_TYPE") = "TABLE" Then
cboTables.AddItem RSTable.Fields("TABLE_NAME")
End If
RSTable.MoveNext
Loop
RSTable.Close
Set RSTable = Nothing
'关闭连接
CTN.Close
Set CTN = Nothing
If cboTables.ListCount <> 0 Then cboTables.ListIndex = 0
Exit Sub
ErrorHandler:
MsgBox Error$
End Sub
Private Sub FillcboFields()
Dim X As Integer
Dim CTable As String
Combo2.Clear
CTable = "[" & cboTables.Text & "]"
Set CTN = New ADODB.Connection
Set RSTable = New ADODB.Recordset
CTN.ConnectionString = ConSTR
CTN.Open
Set RSRc = New ADODB.Recordset
RSRc.ActiveConnection = CTN
RSRc.Open CTable, , , , adCmdTable
For X = 0 To RSRc.Fields.Count - 1
If RSRc.Fields(X).Name <> "ID" Then
Combo2.AddItem RSRc.Fields(X).Name
End If
Next X
RSRc.Close
Set RSRc = Nothing
CTN.Close
Set CTN = Nothing
If Combo2.ListCount <> 0 Then Combo2.ListIndex = 0
End Sub
[解决办法]
先测试下连接语句能不能通过,如果不能查下服务器的mysql是否民对外开放,如果能连接上,建就是你绑定到控件的代码问题了。