搜索验证?

时间:2018-07-05 15:40:14

标签: vb.net

当前,当通过客户ID搜索数据库时,如果用户输入的内容不是客户ID之一,则结果将输出每个客户。如何验证用户输入?

这是代码

    Private Sub DisplayCustomer(CustomerID As Integer)
    If DbConnect() Then
        Dim SQLCmd As New OleDbCommand
        With SQLCmd
            .Connection = cn
            .CommandText = "Select * From Tbl_Customer Where CustomerID = @SearchID"
            .Parameters.AddWithValue("@SearchID", CustomerID)
            Dim rs As OleDbDataReader = .ExecuteReader()


            If rs.Read Then
                CurrentCustomerID = CustomerID
                Txt_CustID.Text = rs("CustomerID")
                PublicCustomerID = Txt_CustID.Text
                txtLastname_Customerform.Text = rs("Secondname")
                txtFirstname_Customerform.Text = rs("First name")
                txtAddress_Customerform.Text = rs("Address")
                txtPostcode_Customerform.Text = rs("Postcode")
                datDOB_Customerform.Value = rs("DOB")
                txtPhonenumber_Customerform.Text = rs("Phone number")



            End If
            rs.Close()

0 个答案:

没有答案