Example sorurce code for database
Hello my friend try this code:
This code is design for Visual Basic 6.0
Function for Connection and recordset string.
Public Sub connection(ByRef dConnection As ADODB.connection, ByVal dLocation As String)
dConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dLocation & ";Persist Security Info=False;"
'======End of Connection String======
Public Sub recordset(ByRef sRecordset As ADODB.recordset, ByRef sConnection As ADODB.connection, ByVal sSQl As String)
.CursorLocation = adUseClient
.Open sSQl, sConnection, adOpenKeyset, adLockOptimistic
'======End Recordset String========
How to apply the above function?
'====== Command Save Button========
Private Sub cmdsave_Click()
Dim cn3 As New ADODB.connection
Dim rs3 As New ADODB.recordset
Call connection(cn3, App.Path & "\CASGC.mdb")
Call recordset(rs3, cn3, "Select * from Debtor_Creditor_Account")
Set dtglobal.DataSource = rs3.DataSource
.Fields("Code") = txtCode.Text
.Fields("Description") = txtDescription.Text
.Fields("Tag") = cbotag.Text
MsgBox "New Account has been Added", vbInformation
Set cn3 = Nothing
Set rs3 = Nothing
'=======end of Command Save button=====
The advantage of using this code is setting your database connection is you have a reliable connection towards your database where ever you place your database you can you don't to remount you databse connection control. Also you are no longer need to use a ADO control or DAO control just copy the function and paste it in your coding area and call the function and you have now a working database and recordset connection string.
For more details regarding how to apply this code just email me at this address: firstname.lastname@example.org to get more codes. thanks..
Please rate this Solution.
Jul 08, 2009 |
Microsoft Visual Basic 6.0 for PC