将两个不同列中的两个值显示在一个文本框中

时间:2014-02-14 17:09:37

标签: vb.net

我试图在文本框中的两个不同的表中显示两个与特定机构相关的值。

我写的代码没有显示“advisor_name”,只显示“Influence_weight_name”。而且我还希望两个名称都显示在一行上,因此最终产品应如下所示:顾问名称 - 重量名称

有人可以帮忙吗?

以下是我的代码:

Dim totalRecords As Integer = sqlTableInstitution.Rows.Count
            Dim advisorText As String = ""
            Dim weightText As String = ""

            If IsDBNull(sqlTableInstitution.Rows(0)("advisor_name")) <> True Then
                advisorText = sqlTableInstitution.Rows(0)("advisor_name")
            End If

            If IsDBNull(sqlTableInstitution.Rows(0)("Influence_weight_name")) <> True    Then
            weightText = weightText & "-" & sqlTableInstitution.Rows(0)("Influence_weight_name")
           End If
Textbox1.text = advisorText
Textbox1.text = weightText

3 个答案:

答案 0 :(得分:2)

Textbox1.text = advisorText + " " + weightText

答案 1 :(得分:1)

Private Function GetData() As String
  Dim totalRecords As Integer = sqlTableInstitution.Rows.Count
  Dim advisorText As String = ""
  Dim weightText As String = ""
  Dim result As String
  If Not IsDBNull(sqlTableInstitution.Rows(0)("advisor_name")) Then
    advisorText = sqlTableInstitution.Rows(0)("advisor_name")
    If Not IsDBNull(sqlTableInstitution.Rows(0)("Influence_weight_name")) Then
      weightText = sqlTableInstitution.Rows(0)("Influence_weight_name")
      result = String.Format("{0}-{1}",advisorText, weightText)
    End If
  End If
  Return result
End Function

答案 2 :(得分:1)

那是因为当你到达这一行时

Textbox1.text = weightText

您将Textbox1.Text替换为weightText,而不是将其与weightText

连接

尝试替换以下代码

Textbox1.text = advisorText
Textbox1.text = weightText

使用此代码

Textbox1.Text = advisorText & weightText