How do i save some data in a database (in access) and get the information when ever i want????
Printable View
How do i save some data in a database (in access) and get the information when ever i want????
A search will usually work wonders.
ADO Tutorial
hi there,
Regarding the updation and retrieval of data from the database
you need to take care of few points
1.Firstly you need to set connection with the database.
2.open the recordset and write a query
3.Write a procedure for updation and retrieval of data shown below.
Here i m using ADO Connection
Option Explicit
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Private Sub cmdRetrieve_Click()
'****************************************************
' This procedure is used to retrieve data from the database
'****************************************************
Set rs = New ADODB.Recordset
rs.Open "select * from amount", cn, adOpenKeyset, adLockOptimistic
If Not rs.RecordCount = 0 Then
txtname = rs("name")
txtroute = rs("route")
txtyear = rs("year")
Else
MsgBox "No record Exists"
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub cmdsave_Click()
'****************************************************
'This particular event will save the textdata in their respectice fields
'****************************************************
Set rs = New ADODB.Recordset
rs.Open "select * from amount", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs("name") = txtname
rs("route") = txtroute
rs("year") = txtyear
rs.Update
MsgBox "The record is saved"
rs.Close
Set rs = Nothing
End Sub
Private Sub Command1_Click()
'*********************************************
'This Statement is used to end the application
'*********************************************
End
End Sub
Private Sub Form_Load()
'*****************************************
'This will provide you with the connection
'*****************************************
Set cn = New ADODB.Connection
Dim strconn As String
strconn = "Dsn=hemant"
cn.Open strconn
End Sub
---Here I need to mention I am using a dsn instead of directly giving the path.
To create a dsn
1 In Setting Click on control panel
2.Then in control panel you will find odbc data sources<click on it>
3.Then in odbc click on configure
a)out there give a dsn name and the reqd details
b) Then Click on select and select the reqd database
For using ado connection go to Project>References and select Microsoft Acticex data objects 2.0 library
if you want any assistance contact at [email protected]
You may want to use a newer version of ADO than 2.0. The
current version is 2.8, but I would recommend using 2.7 because
it has more bug fixes in it. You can download it from M$. Search
for "MDAC 2.7". Also, don't forget that using a dsn will
depend on how it is set up. It could be machine, user, or file
specific. Also, to create the dsn you need to select the type and
click "New" not configure. Configure is for modifing an existing
dsn.
;)