我可以将数据从SQL显示到标签

时间:2013-07-17 05:22:35

标签: sql vb.net

如何在VB.NET中将SQL WORKGROUP 2005中的数据显示到我的标签?

到目前为止,这是我尝试过的:

Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    Dim strSQL As String
    Dim Conn As OdbcConnection = New OdbcConnection("Label6=RATE")

    strSQL = SELECT * FROM [PESORATE]

    Dim catCMD As OdbcCommand = New OdbcCommand(strSQL, Conn)

    Conn.Open()

    Dim myReader As OdbcDataReader = catCMD.ExecuteReader()

    If myReader.HasRows Then
        Do While myReader.Read()
            'the SqlDataReader returns typed data.  You must use the
            'proper get method for the type you are retrieving.
            '(GetInt32, GetString, GetBoolean etc.)
            Write(myReader.GetString(myReader.GetOrdinal([Rate]))))
            Write("<BR>")
        Loop
    Else
        Write("No records found!")
    End If

    myReader.Close()
    Conn.Close()

2 个答案:

答案 0 :(得分:1)

您的连接字符串似乎不正确:

Dim Conn As OdbcConnection = New OdbcConnection("Label6=RATE")

您需要更正它以指向现有DSN或创建DSN less连接字符串。

答案 1 :(得分:0)

尝试编码

Label6.text =您的数据