Smu2015
Messages postés13Date d'inscriptionmardi 15 avril 2003StatutMembreDernière intervention 5 juillet 2007
-
2 juil. 2005 à 15:04
VPNVB
Messages postés58Date d'inscriptiondimanche 7 août 2005StatutMembreDernière intervention20 août 2008
-
24 avril 2008 à 13:16
Bonjour a tous :)
Voila,
Je cherche a connecter une base SQlite version 3+ avec VB6 malheuresement, je n'ai rien trouvé...
Il y a bien AGS_SQlite.dll mais cette version est faite pour les bases
versions 2.8.* (versions ne comprennent pas le ALTER TABLE) et donc la
connection est un echec...
Si quelqu'un a une solution, je lui serait tres reconnaissant de me la communiquer :)
'//Synposis:
'//1. Create an ADO connection
'//2. Enable Read Data button if the table exists
Private Sub Form_Load()
On Error GoTo Trap
Set mConn = New ADODB.Connection
mConn.Open "Provider=OleSQLite.SQLiteSource.1; Data Source=C:\public\customer.dat"
If HasCustTable Then
Me.Read.Enabled = True
End If
Exit Sub
Trap:
MsgBox Err.Description
End Sub
'//Synposis:
'//1. Create a table named cust if it does not exist. If the table exits,
'//delete all records from the table.
'//2. Insert some records into cust table
'//3. Update the records using parameters which makes it easy for
'//binary data manipulation
Private Sub Create_Click()
On Error GoTo Trap
Dim cmd As New ADODB.Command
cmd.ActiveConnection = mConn
If HasCustTable Then 'delete all data from the table if table exists
cmd.CommandText = "DELETE FROM cust;"
Else 'create cust table if it does not exists
cmd.CommandText = "CREATE TABLE cust(ID INTEGER PRIMARY KEY, Name VARCHAR(60), "
+ "Address VARCHAR(120), Picture BLOB);"
End If
cmd.Execute
cmd.CommandText = ""
'insert data
Dim I As Integer
For I = 100 To 110
cmd.CommandText = cmd.CommandText + "INSERT INTO cust (ID, Name) VALUES (" & I & ", 'Sean " & I & "');"
Next I
cmd.Execute
'update records with Parameters
Dim BA(999) As Byte
For I = 0 To 999
BA(I) = (I + 1) Mod 256
Next I
Dim params(2) As Parameter
Set params(0) = New ADODB.Parameter
params(0).Type = adInteger 'integer
params(0).Value = 100
Set params(1) = New ADODB.Parameter
params(1).Type = adBSTR 'string
params(1).Value = "1010 Main St, Salem, OR"
Set params(2) = New ADODB.Parameter
params(2).Type = adBinary
params(2).Value = BA
params(2).Size = 1000
cmd.CommandText = "UPDATE cust SET Address=?, Picture=? WHERE ID=?;"
'add parameters according to commend text
cmd.Parameters.Append params(1)
cmd.Parameters.Append params(2)
cmd.Parameters.Append params(0)
cmd.Execute
'using transaction
params(0).Value = 101
mConn.BeginTrans
cmd.Execute
mConn.RollbackTrans 'You will see the address is NOT updated
params(0).Value = 102
mConn.BeginTrans
cmd.Execute
mConn.CommitTrans 'Address is updated when read back
Set cmd = Nothing
MsgBox "Done"
Exit Sub
Trap:
MsgBox Err.Description
End Sub
'//Synposis:
'//Create a recordset to get all data from cust table and present the
'//data in a data grid.
'//To view the binary data read back from the database, you may open
'//open a watch window in the debug mode
Private Sub Read_Click()
Dim BA() As Byte
On Error GoTo Trap
Me.MSHFlexGrid1.Clear
Dim Rs As New ADODB.Recordset
Rs.Open "SELECT * FROM cust;", mConn
If Not Rs.EOF Then
BA = Rs("Picture").Value 'add to watch window to view byte array
End If
Set Me.MSHFlexGrid1.Recordset = Rs
Exit Sub
Trap:
MsgBox Err.Description
End Sub
'//Synposis:
'//Clear all data from the data grid
Private Sub Clear_Click()
Me.MSHFlexGrid1.Clear
End Sub
'//Synposis:
'//Check if the cust table exists. Return true if it does. Return false
'//otherwise.
Private Function HasCustTable() As Boolean
Dim Rs As ADODB.Recordset
Set Rs = mConn.OpenSchema(adSchemaTables)
While Not Rs.EOF
If Rs("table_name").Value = "cust" Then
HasCustTable = True
GoTo funExit
End If
Rs.MoveNext
Wend
funExit:
Rs.Close
Set Rs = Nothing
End Function
VPNVB
Messages postés58Date d'inscriptiondimanche 7 août 2005StatutMembreDernière intervention20 août 2008 24 avril 2008 à 13:16
Salut,
je te Recommande de ne pas utilisé se Fournisseur OleDB
puice qu'il demande L'activation !
si tu redistribute se fournisseur avec votre logiciel, il ne sera pas opérationaile (si je suis sur)
je te recommande d'utilisé SQLIteCom ou SQL.Net Data Provider
Pour Telecharger SQLIteCom, Aller à:
http://www.newobjects.com/downloads/AXPack1.exe