如何在文本框vb.net中访问和显示ID(自动增量)

时间:2015-09-14 15:13:21

标签: vb.net ms-access-2010

我的代码出了什么问题?

Sub _PID()
    Try
        cn = New OleDbConnection(conn)
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        Else
            cn.Close()

        End If
        cmd = New OleDbCommand("SELECT MAX(_PID) FROM PatientRegistration", cn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        If dr.Read = True Then
            Me.txtPID.Text = dr.Item(0) + 1
        Else
            Exit Sub

        End If
    Catch ex As Exception
        MsgBox(ex.Message)

    End Try

0 个答案:

没有答案