下面的Visual Basic 6.0代码有什么作用?但它已被用于搜索功能,我不清楚它。所以请解释它的作用。
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
答案 0 :(得分:5)
尚无人明确表示rs
必须声明为As New RecordSet
,以便Set rs = Nothing
与Set rs = New RecordSet
实际上有效相同。
答案 1 :(得分:3)
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
简短摘要:向用户询问名称,并在标签或文本框中显示用户的数据。
答案 2 :(得分:1)
它对数据库进行两次搜索。第一次搜索的结果用于填充一些文本框。第二次搜索的结果......我不知道他们在做什么。
答案 3 :(得分:1)
它基于名为e_no
的列从数据库中查找数据,将找到的行中的信息加载到TextBox控件中,然后在数据库中重新查询所有emp
行。