Reputation: 13811
What does this Visual Basic 6.0 code below do? However it has been used for a search function, I'm not clear with it. So please explain what it does.
Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Employee No whose details u want to know: ")
Set rs = Nothing
str = "select * from emp where e_no=" & key
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
End Sub
Upvotes: 2
Views: 2204
Reputation: 61437
Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Employee No whose details u want to know: ") ''// query the user for a name
Set rs = Nothing
str = "select * from emp where e_no=" & key ''//create sql query on the fly
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly ''// create a connection to an sql database
txtNo.Text = rs(0) ''//assign the results of the query to input fields or labels
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic ''// creates a new sql connection and load the whole emp table
End Sub
Short summary: Ask the user for a name and display the data of the user in labels or textboxes.
Upvotes: 3
Reputation: 10931
The point no one yet has explicitly said is rs
must be declared As New RecordSet
so that the Set rs = Nothing
just means effectively the same as Set rs = New RecordSet
.
Upvotes: 5
Reputation: 125689
It looks up data from a database based on a column called e_no
, loads information from the found row into TextBox controls, and then re-queries the database for all emp
rows.
Upvotes: 1
Reputation: 70307
It makes two searches against the database. The result of the first search is used to populate some text boxes. The results of the second search... well I have no idea what they are doing with it.
Upvotes: 1