Как мне подружить DataGrid с mySQL'ем?
Т.е. чтоб в датагриде был результат запроса, который я в нём указал.
Private Sub Form_Load()
Dim adoConnect As adodb.Connection
Set adoConnect = New adodb.Connection
Dim record As adodb.Recordset
Dim strConnect As String
strConnect = "DRIVER={MySQL ODBC 3.51 Driver};Server=server;Port=3306;Option=3;Stmt=;Database=global;Uid=user;Pwd=mypass;"
adoConnect.Open strConnect
Set record = New adodb.Recordset
record.ActiveConnection = adoConnect
record.Properties("IRowsetIdentity") = True
record.Open "select * from ware1", , adOpenStatic, adLockBatchOptimistic
Set DataGrid1.DataSource = record
End Sub
Private Conn As ADODB.Connection, Rec As ADODB.Recordset
Private Sub Command1_Click()
Dim strConnect As String
strConnect = "DRIVER={MySQL ODBC 3.51 Driver};Server=lab;Database=base1;Uid=root;Pwd=;"
Set Conn = New ADODB.Connection
' Init params
With Conn
.CommandTimeout = 15
.ConnectionString = strConnect
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.IsolationLevel = adXactReadCommitted
.Mode = adModeReadWrite Or adModeShareDenyNone
.Open
End With
' Init recordset
Set Rec = New ADODB.Recordset
With Rec
Set .ActiveConnection = Conn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Source = "select * from table1"
.Open
End With
Rec.Properties("IRowsetIdentity") = True
Set Me.DataGrid1.DataSource = Rec
End Sub
Private Sub Command2_Click()
' Clear garbage
Rec.Close
Set Rec = Nothing
Conn.Close
Set Conn = Nothing
End Sub
Rec.Close
Получается, что все зависит от грида
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2