MIGRAR ACCESS P/ MYSQL 5.5 C/ VB6
Boa tarde pessoal, estou usando conexão com acess da seguinte forma
Dim DB As Database
Dim RS As Recordset
Set DB = Workspaces(0).OpenDatabase(Conexao & [Ô]\dados.mdb[Ô], False, False, [Ô]MS Access;PWD=projeto[Ô]) [ô]abre o banco de dados com senha
Set RS = DB.OpenRecordset([Ô]select * from Seguros order by seguradora[Ô])
esta tudo ok funcionando, porém quero mudar o bando de dados p/ Mysql 5.5 e gostaria de uma dica
banco de dados seguradora
user root
localhost
senha 12345
Dim DB As Database
Dim RS As Recordset
Set DB = Workspaces(0).OpenDatabase(Conexao & [Ô]\dados.mdb[Ô], False, False, [Ô]MS Access;PWD=projeto[Ô]) [ô]abre o banco de dados com senha
Set RS = DB.OpenRecordset([Ô]select * from Seguros order by seguradora[Ô])
esta tudo ok funcionando, porém quero mudar o bando de dados p/ Mysql 5.5 e gostaria de uma dica
banco de dados seguradora
user root
localhost
senha 12345
JLSMA
Dá uma olhada nesse fórum
http://vbmania.com.br/pages/index.php?varModulo=Forum&varMethod=abrir&varID=334819
Dá uma olhada nesse fórum
http://vbmania.com.br/pages/index.php?varModulo=Forum&varMethod=abrir&varID=334819
Amigo você esta usando DAO use ADO.
Precisar instalar drivers ODBC para comunicar VB6 e MYSQL - tanto remoto como local.
Aqui no próprio site tem muita coisa.
Precisar instalar drivers ODBC para comunicar VB6 e MYSQL - tanto remoto como local.
Sub Conexao_Conectar_Banco()
On Error GoTo Rotina_Erro
SERVIDOR = GetIni([Ô]MySQL_Connect[Ô], [Ô]SERVIDOR[Ô], App.Path & [Ô]\MySQL.ini[Ô])
PORTA = GetIni([Ô]MySQL_Connect[Ô], [Ô]PORTA[Ô], App.Path & [Ô]\MySQL.ini[Ô])
USUARIO = GetIni([Ô]MySQL_Connect[Ô], [Ô]USUARIO[Ô], App.Path & [Ô]\MySQL.ini[Ô])
SENHA = GetIni([Ô]MySQL_Connect[Ô], [Ô]SENHA[Ô], App.Path & [Ô]\MySQL.ini[Ô])
BASE = GetIni([Ô]MySQL_Connect[Ô], [Ô]BASEDEDADOS[Ô], App.Path & [Ô]\MySQL.ini[Ô])
CONN.Open [Ô]Driver={MySQL ODBC 5.1 Driver};Server=[Ô] & SERVIDOR & [Ô];Port=[Ô] & 3306 & [Ô];Database=[Ô] & BASE & [Ô];User=[Ô] & USUARIO & [Ô];Password=[Ô] & SENHA& [Ô];Option=3;[Ô]
Exit Sub
Rotina_Erro:
End Sub
Aqui no próprio site tem muita coisa.
OLIVEIRA AGRADEÇO A DICA, A CONEXÇÃO ESTA FUNCIONANDO CONFORME ABAIXO:, PORéM GOSTARIA DE UMA DICA PARA CARREGAR DOS DADOS DO MYSQL NO MSFLEXGRI QUE JA TENHO NO SISTEMA
No Modulo
Public MyDB As ADODB.Connection
Public Function ConectaMySql()
Set MyDB = New ADODB.Connection
MyDB.ConnectionString = [Ô]Driver=MySQL ODBC 5.1 Driver; DATABASE=Serraria; SERVER=localhost; UID=root; PASSWORD=12345[Ô]
MyDB.Open
End Function
================================
Dim RS As ADODB.Recordset
Dim RS_FLEX As ADODB.Recordset
No Form Load
ConectaMySql
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseServer
RS.Open [Ô]Select * from Clientes[Ô], MyDB, adOpenStatic, adLockOptimistic, adCmdText
Set RS_FLEX = New ADODB.Recordset
RS_FLEX.CursorLocation = adUseServer
RS_FLEX.Open [Ô]Select * from Clientes[Ô], MyDB, adOpenStatic, adLockOptimistic, adCmdText
EU PRECISO CARREGAR O MSFLEXGRID COM OS DADOS DA RS_FLEX, COM ACCESS ESTAVA USANDO O DATA1 E REFERENCIANDO NO FLEX.DATASOURCE
Private Sub Flex_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
colDown = FindColumn(x, y)
End Sub
Private Sub Flex_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If colDown <> -1 Then
SetCursor LoadCursor(0, IDC_CROSS)
End If
Me.lblMousexy = [Ô]([Ô] & x & [Ô],[Ô] & y & [Ô])[Ô]
If x + 346 >= Flex.Width Then
If Flex.LeftCol <> Flex.Cols Then
Flex.LeftCol = Flex.LeftCol + 1
ColLeftRight = 0
End If
End If
If x <= 345 Then
If Flex.LeftCol <> Flex.Cols Then
If Flex.LeftCol <> 0 Then
Flex.LeftCol = Flex.LeftCol - 1
End If
ColLeftRight = 1
End If
End If
Exit Sub
End Sub
Private Sub Flex_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim t As Variant
colUp = FindColumn(x, y)
If colDown <> -1 And colUp <> -1 Then
If colDown <> colUp Then
[ô] reverse columns
With Flex
For y = 0 To .Rows - 1
t = .TextMatrix(y, colDown)
.TextMatrix(y, colDown) = .TextMatrix(y, colUp)
.TextMatrix(y, colUp) = t
Next y
End With
End If
End If
colDown = -1
SetCursor LoadCursor(0, IDC_ARROW)
Exit Sub
End Sub
Private Function FindColumn(x As Single, y As Single)
[ô]
[ô] If x,y identifies a header column, return the column else -1
[ô]
Dim i, J As Long
Dim cellX As Long
With Flex
If .TopRow = 1 And y >= 0 And y < .RowHeight(0) Then [ô]in the header
For i = .LeftCol To .Cols - 1
If x >= cellX And x < cellX + .ColWidth(i) Then
Select Case ColLeftRight
Case 0
FindColumn = i
Exit Function
Case 1
FindColumn = i
Exit Function
End Select
End If
cellX = cellX + .ColWidth(i)
Next i
End If
End With
FindColumn = -1
Exit Function
End Function
Private Sub Form_Activate()
With Flex
[ô] tamanho das colunas
.ColWidth(0) = 3000
.ColWidth(1) = 3000
.ColWidth(2) = 1200
.ColWidth(3) = 1200
[ô]Titulo das Colunas
.TextMatrix(0, 0) = [Ô]Nome/Razão Social[Ô]
.TextMatrix(0, 1) = [Ô]Fantasia/Apelido[Ô]
.TextMatrix(0, 2) = [Ô]Telefone[Ô]
.TextMatrix(0, 3) = [Ô]Celular[Ô]
End With
End Sub
Private Sub Flex_Click()
CmdAltera.Enabled = True [ô]
With Flex
If .Row > 0 Then
.Col = 0
.ColSel = .Cols - 1
End If
End With
Exit Sub
End Sub
No Modulo
Public MyDB As ADODB.Connection
Public Function ConectaMySql()
Set MyDB = New ADODB.Connection
MyDB.ConnectionString = [Ô]Driver=MySQL ODBC 5.1 Driver; DATABASE=Serraria; SERVER=localhost; UID=root; PASSWORD=12345[Ô]
MyDB.Open
End Function
================================
Dim RS As ADODB.Recordset
Dim RS_FLEX As ADODB.Recordset
No Form Load
ConectaMySql
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseServer
RS.Open [Ô]Select * from Clientes[Ô], MyDB, adOpenStatic, adLockOptimistic, adCmdText
Set RS_FLEX = New ADODB.Recordset
RS_FLEX.CursorLocation = adUseServer
RS_FLEX.Open [Ô]Select * from Clientes[Ô], MyDB, adOpenStatic, adLockOptimistic, adCmdText
EU PRECISO CARREGAR O MSFLEXGRID COM OS DADOS DA RS_FLEX, COM ACCESS ESTAVA USANDO O DATA1 E REFERENCIANDO NO FLEX.DATASOURCE
Private Sub Flex_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
colDown = FindColumn(x, y)
End Sub
Private Sub Flex_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If colDown <> -1 Then
SetCursor LoadCursor(0, IDC_CROSS)
End If
Me.lblMousexy = [Ô]([Ô] & x & [Ô],[Ô] & y & [Ô])[Ô]
If x + 346 >= Flex.Width Then
If Flex.LeftCol <> Flex.Cols Then
Flex.LeftCol = Flex.LeftCol + 1
ColLeftRight = 0
End If
End If
If x <= 345 Then
If Flex.LeftCol <> Flex.Cols Then
If Flex.LeftCol <> 0 Then
Flex.LeftCol = Flex.LeftCol - 1
End If
ColLeftRight = 1
End If
End If
Exit Sub
End Sub
Private Sub Flex_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim t As Variant
colUp = FindColumn(x, y)
If colDown <> -1 And colUp <> -1 Then
If colDown <> colUp Then
[ô] reverse columns
With Flex
For y = 0 To .Rows - 1
t = .TextMatrix(y, colDown)
.TextMatrix(y, colDown) = .TextMatrix(y, colUp)
.TextMatrix(y, colUp) = t
Next y
End With
End If
End If
colDown = -1
SetCursor LoadCursor(0, IDC_ARROW)
Exit Sub
End Sub
Private Function FindColumn(x As Single, y As Single)
[ô]
[ô] If x,y identifies a header column, return the column else -1
[ô]
Dim i, J As Long
Dim cellX As Long
With Flex
If .TopRow = 1 And y >= 0 And y < .RowHeight(0) Then [ô]in the header
For i = .LeftCol To .Cols - 1
If x >= cellX And x < cellX + .ColWidth(i) Then
Select Case ColLeftRight
Case 0
FindColumn = i
Exit Function
Case 1
FindColumn = i
Exit Function
End Select
End If
cellX = cellX + .ColWidth(i)
Next i
End If
End With
FindColumn = -1
Exit Function
End Function
Private Sub Form_Activate()
With Flex
[ô] tamanho das colunas
.ColWidth(0) = 3000
.ColWidth(1) = 3000
.ColWidth(2) = 1200
.ColWidth(3) = 1200
[ô]Titulo das Colunas
.TextMatrix(0, 0) = [Ô]Nome/Razão Social[Ô]
.TextMatrix(0, 1) = [Ô]Fantasia/Apelido[Ô]
.TextMatrix(0, 2) = [Ô]Telefone[Ô]
.TextMatrix(0, 3) = [Ô]Celular[Ô]
End With
End Sub
Private Sub Flex_Click()
CmdAltera.Enabled = True [ô]
With Flex
If .Row > 0 Then
.Col = 0
.ColSel = .Cols - 1
End If
End With
Exit Sub
End Sub
Olá, Amigo
No seu caso os dados não estão mais no DATA e sim no RS_FLEX
Set RS_FLEX = New ADODB.Recordset
RS_FLEX.CursorLocation = adUseServer
RS_FLEX.Open [Ô]Select * from Clientes[Ô], MyDB, adOpenStatic, adLockOptimistic, adCmdText
No seu caso os dados não estão mais no DATA e sim no RS_FLEX
RS_FLEX!NOME
RS_FLEX!ENDERECO
RS_FLEX!CEP
Tópico encerrado , respostas não são mais permitidas