Retrieving Info from DB

how to retrirve particular information from database

Page 1 of 1

2 Replies - 556 Views - Last Post: 09 February 2010 - 09:14 PM Rate Topic: -----

#1 aarthii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-February 10

Retrieving Info from DB

Posted 09 February 2010 - 06:39 AM

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 & " '

Is This A Good Question/Topic? 0
  • +

Replies To: Retrieving Info from DB

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,428
  • Joined: 23-August 08

Re: Retrieving Info from DB

Posted 09 February 2010 - 06:50 AM

ADO Tutorial
Was This Post Helpful? 0
  • +
  • -

#3 Kinwang2009  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 76
  • Joined: 07-February 10

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1