Postada em 19/02/2008 16:43 hs
Olá a todos, estou fazendo um protótipo em vb 6 com ado e mysql, mas estou com problemas na hora de preencher um flexgrid. Meu código:
Conexão: Set connection = New ADODB.connection Set recordSet = New ADODB.recordSet
ConectaMySQL = "driver={MySQL ODBC 3.51 Driver};" & "server=localhost;" & "User=root;Password=root;database=mecanica;" & "Option=3" connection.Open ConectaMySQL
Busca para preencher o flexgrid: recordSet.Open "SELECT * FROM cliente order by nome", connection, 1, 1, 1 MSFlexGrid1.Cols = 10 MSFlexGrid1.ColWidth(0) = 500 MSFlexGrid1.TextMatrix(0, 0) = "nº" For I = 0 To recordSet.Fields.Count - 1 MSFlexGrid1.ColAlignment(I) = vbCenter MSFlexGrid1.ColWidth(I + 1) = 1500 MSFlexGrid1.TextMatrix(0, I + 1) = recordSet.Fields(I).Name Next MSFlexGrid1.Rows = recordSet.RecordCount + 1 I = 1 Do While Not recordSet.EOF MSFlexGrid1.TextMatrix(I, 0) = I MSFlexGrid1.TextMatrix(I, 1) = recordSet(0) MSFlexGrid1.TextMatrix(I, 2) = recordSet(1) MSFlexGrid1.TextMatrix(I, 3) = recordSet(2) MSFlexGrid1.TextMatrix(I, 4) = recordSet(3) MSFlexGrid1.TextMatrix(I, 5) = recordSet(4) MSFlexGrid1.TextMatrix(I, 6) = recordSet(5) MSFlexGrid1.TextMatrix(I, 7) = recordSet(6) MSFlexGrid1.TextMatrix(I, 8) = recordSet(7) MSFlexGrid1.TextMatrix(I, 9) = recordSet(8) I = I + 1 recordSet.MoveNext Loop
O problema está no recordSet.RecordCount, que está retornando -1, quando deveria retornar 5.
O que eu posso fazer?
Obrigado pela ajuda!
|