Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从数据库中显示和清除标签中的值_Mysql_Vb.net_Mysql Workbench - Fatal编程技术网

Mysql 从数据库中显示和清除标签中的值

Mysql 从数据库中显示和清除标签中的值,mysql,vb.net,mysql-workbench,Mysql,Vb.net,Mysql Workbench,你好 我有一个名为Customer的数据表,其属性为CustomerID、Firstname和姓氏 到目前为止,我已经成功地将正确的客户连接到正确的customerID来显示标签。在我编写CustomerID时,它会在标签中显示客户的名字和姓氏 例如,如果我在文本框中写入5022(是customerID),则lblFirstname=Jon和lblSurname=Snow。然而,如果我继续写,比如502222,那么它仍然会显示乔恩·斯诺。我只想让它在完全正确的情况下出现,这意味着如果我写了一个不

你好

我有一个名为
Customer
的数据表,其属性为
CustomerID
Firstname
姓氏

到目前为止,我已经成功地将正确的客户连接到正确的customerID来显示标签。在我编写CustomerID时,它会在标签中显示客户的名字和姓氏

例如,如果我在文本框中写入5022(是customerID),则
lblFirstname=Jon
lblSurname=Snow
。然而,如果我继续写,比如502222,那么它仍然会显示乔恩·斯诺。我只想让它在完全正确的情况下出现,这意味着如果我写了一个不存在的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()
Dim customerID为整数
如果txtCustomer.Text为“”,则
CustomerID=CInt(txtCustomer.Text)
myCommand.CommandText=“从CustomerID=“&CustomerID&”的客户中选择名字和姓氏”
myAdapter=新的MySqlDataAdapter(myCommand)
myTable=新数据表
myAdapter.Fill(myTable)
如果myTable.Rows.Count>0,则
lblFirstname.Text=myTable.Rows(0)(“Firstname”).ToString()
lblSurname.Text=myTable.Rows(0)(“姓氏”).ToString()
如果结束
其他的
lblFirstname.Text=“”
lblSurname.Text=“”
如果结束
myConnection.Close()

有什么建议吗?

似乎您在向标签添加文本时遇到了问题。。您是否在代码的某个地方为标签分配了变量。如果你有,把它们拿走,我想这样就行了