1

テーブルでいくつかのデータを選択したいので、次のコードを使用します。

Public Class frmLogin
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            Dim t As New DataTable
    Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
    Dim cmd As OleDbCommand
    Dim reader As OleDbDataReader = Nothing
    Dim tuser As String = txtUsername.Text

    Dim sql As String = "SELECT * FROM dosen WHERE nip=tuser"
    Try
        cmd = New OleDbCommand(sql, conn)
        reader = cmd.ExecuteReader()

        While reader.Read
            MessageBox.Show(reader.GetString(0).ToString & _
                            vbTab & vbTab & reader.GetString(1).ToString)
        End While
    Finally
        If reader IsNot Nothing Then reader.Close()
    End Try

End Sub

しかし、reader = cmd.ExecuteReader()行にエラーがあります。誰でも私を助けることができますか?

4

1 に答える 1

0

間違いをなおす。コードは

Dim reader As OleDbDataReader ' no need for nothing
Dim adapter As New OleDbDataAdapter()
Dim sql As String = "SELECT * FROM dosen WHERE nip='" & tuser & "'"

tuser は変数であり、コンテンツではありません

于 2013-05-02T05:40:43.840 に答える