2

你好

Customer我有一个用属性调用的数据表CustomerIDFirstnameSurname

到目前为止,我已经成功地显示了与正确客户 ID 相关联的正确客户的标签。在我编写 CustomerID 时,它会在标签中显示客户的名字和姓氏。

例如,如果我在文本框中输入 5022(is a customerID),则lblFirstname = Jonand lblSurname = Snow。但是,如果我继续写,比如 502222,那么它仍然会显示 Jon Snow。我只想让它出现在它完全正确的情况下,这意味着如果我写一个不存在的 customerID,标签就会清除。

到目前为止,这是我的代码:

       Dim customerID As Integer

    If txtCustomer.Text <> "" Then
        CustomerID = CInt(txtCustomer.Text)
        myCommand.CommandText = "Select firstname, surname from customer where CustomerID = " & CustomerID & ""
        myAdapter = New MySqlDataAdapter(myCommand)
        myTable = New DataTable
        myAdapter.Fill(myTable)



        If myTable.Rows.Count > 0 Then
            lblFirstname.Text = myTable.Rows(0)("Firstname").ToString()
            lblSurname.Text = myTable.Rows(0)("Surname").ToString()
        End If

    Else
        lblFirstname.Text = ""
        lblSurname.Text = ""
    End If
    myConnection.Close()

有什么建议么?

4

1 回答 1

3

It seems that you have a problem with adding text to the labels.. Have you somewhere in your code assigned variables to your labels. If you have, remove them, I think that'll do the trick.

于 2013-05-13T15:05:56.897 回答