Hi..
I just want to know how to retrieve a particular information from database..
that is
i have the fields like name regno dept etc..
and i have to retrieve only the name xxx which is entered by user..
I got the input from the user using text box(so text1.text contains the input name)
In adodc control i gave the command text(sql) in properties as
select * from table1 where name1=' " & text1.text & " '
Retrieving Info from DBhow to retrirve particular information from database
Page 1 of 1
2 Replies - 381 Views - Last Post: 09 February 2010 - 09:14 PM
Replies To: Retrieving Info from DB
#3
Re: Retrieving Info from DB
Posted 09 February 2010 - 09:14 PM
Hi aarthii,
Use the following code, it works fine
Private Sub cmdFind_Click()
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "database.mdb;Mode=Read|Write"
conn.CursorLocation = adUseClient
conn.Open
With cmd
.ActiveConnection = conn
.CommandText = "SELECT * From [tblInfo] where RegNo LIKE '" & txtRegNo.Text & "'"
.CommandType = adCmdText
End With
With rst
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmd
End With
If rst.EOF = False Then
rst.MoveFirst
Do
'Displays found record in Message Box
MsgBox rst!Department
rst.MoveNext
Loop Until rst.EOF = True
rst.Close
Else
MsgBox "No records were found"
End If
conn.Close
Set conn = Nothing
Set cmd = Nothing
Set rst = Nothing
End Sub
Good Luck
Use the following code, it works fine
Private Sub cmdFind_Click()
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "database.mdb;Mode=Read|Write"
conn.CursorLocation = adUseClient
conn.Open
With cmd
.ActiveConnection = conn
.CommandText = "SELECT * From [tblInfo] where RegNo LIKE '" & txtRegNo.Text & "'"
.CommandType = adCmdText
End With
With rst
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmd
End With
If rst.EOF = False Then
rst.MoveFirst
Do
'Displays found record in Message Box
MsgBox rst!Department
rst.MoveNext
Loop Until rst.EOF = True
rst.Close
Else
MsgBox "No records were found"
End If
conn.Close
Set conn = Nothing
Set cmd = Nothing
Set rst = Nothing
End Sub
Good Luck
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|