Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What this Visual Basic 6.0 code do?

Tags:

vb6

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
like image 725
Ant's Avatar asked Apr 21 '26 01:04

Ant's


2 Answers

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.

like image 67
Mark Hurd Avatar answered Apr 23 '26 15:04

Mark Hurd


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.

like image 27
Femaref Avatar answered Apr 23 '26 17:04

Femaref