-5

如何在 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()
4

2 回答 2

1

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

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

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

于 2013-07-17T05:37:10.970 回答
0

试试这段代码

Label6.text = 你的数据

于 2013-07-17T06:02:15.917 回答