无法在访问数据库中添加超过28的记录

时间:2017-12-26 19:51:59

标签: vb.net ms-access-2007 ms-access-2016

我正在使用vb.net和访问创建我的第一个项目。我正在尝试开发一个项目,其中从不同的柜台添加患者的数据。工作正常,直到输入第22或第23条记录。之后,添加新记录会写入上次保存的记录。

检查数据库我删除了一些记录(比如删除后数据库中有13条记录)并尝试添加新记录,它给出了同样的问题,第13条记录被新记录覆盖。

我删除了所有记录,并尝试添加新记录,第一条记录成功输入,但在新记录条目结束后写入最后一条(仅)记录。

我无法理解这个问题

保存数据的代码是

 Private Sub Save()

        'Dim st As String

        Dim str As String
        btnSave_Click = False
        str = check
        If Not str = "" Then
            MsgBox(str, vbInformation, "Patient Registration")
            btnSave_Click = False
            Exit Sub
        End If

        If conn.State = 0 Then
            Module1.openConnection()
        End If

        If Not rsDept Is Nothing Then
            If rsDept.State = 0 Then
                Call openRecordset("SELECT * FROM tblDept", rsDept)
            End If
        Else
            Call openRecordset("SELECT * FROM tblDept", rsDept)
        End If

        If Not rsData Is Nothing Then
            If rsData.State = 0 Then
                Call openRecordset("Select * from tblPatientRecord", rsData)
            End If
        Else
            Call openRecordset("Select * from tblPatientRecord", rsData)
        End If

        conn.BeginTrans()
        On Error GoTo ProcError
        If Not (rsData.BOF And rsData.EOF) Then

            rsData.MoveLast()
            Call addData(rsData)
        Else
            Call addData(rsData)
        End If
        conn.CommitTrans()
        MsgBox("Patient's Record Saved Successfully...!", MsgBoxStyle.Information, "Patient Registration")

        Call loadDataListview()
        Call fieldDisable()
        Call Disable_SearchButtons()
        btnSave_Click = True
        comDepart.Enabled = False
        conn.Close()

ProcError:
        If Err.Number <> 0 Then
            conn.RollbackTrans()
            MsgBox(Err.Number & "   " & Err.Description)
            Call addNewR()
            Exit Sub
        End If

    End Sub


    Private Sub addData(rData As ADODB.Recordset)
        Dim rsPaymentType As New ADODB.Recordset
        'Dim str As String

        If Not (rData.BOF And rsData.EOF) Then
            rData.MoveFirst()
            If rData.RecordCount > 0 Then
                Do
                    If txthn.Text = rData("hNumber").Value Then
                        Call addVisit()
                        conn.Execute("update tblPatientRecord set visitNo = '" & vNo.Text & "' where hNumber = '" & txthn.Text & "'")

                        Call fieldEnable()
                       Exit Sub
                    End If
                    rData.MoveNext()
                Loop Until rData.EOF
            End If
        End If

        rData.AddNew()
        rData("hNumber").Value = txthn.Text
        rData("fName").Value = txtfn.Text
        rData("contactNo").Value = txtContact.Text
        rData("address").Value = txtaddress.Text
        rData("cnic").Value = txtcnic.Text
        'rData("cnic").Value = rCNIC()
        rsData("visitNo").Value = vNo.Text
        rsData("cnicSD").Value = comSD.Text

        ''Add gender as selected

        If radmale.Checked = True Then
            rData("gender").Value = radmale.Text
        ElseIf radfemale.Checked = True Then
            rData("gender").Value = radfemale.Text
        Else
            rData("gender").Value = " - "
        End If

        If txtAge.Text < 105 Or Year(dtAgePicker.Value) < 1915 Then
            Call addAge()
            'MsgBox("data of tblAge added")
        Else
            MsgBox("Please Enter Correct Age ", vbCritical, "")
            txtAge.Select()
            Exit Sub
        End If

        If comRelation.Text = "Select Relation with Patient" Or comRelation.Text = "" Then
            comRelation.Text = "Not Selected"
        End If
        If txtfh.Text = "" Then
            txtfh.Text = "Not Given"
        End If

        Call addRelation()

        'Save Department ID as selected
        If comDepart.Text <> "Select Department" Then
            Call addVisit()
            'MsgBox("data of tblVisit added")
        Else
            MsgBox("Please Enter the Department ", vbCritical, "")
            comDepart.Select()
            Exit Sub
        End If

        If Not rsPaymentType Is Nothing Then
            If rsPaymentType.State = 0 Then
                Call openRecordset("Select * from tblPaymentType", rsPaymentType)
                'MsgBox("Patient record is open" & rsData.State)
            End If
        Else
            Call openRecordset("Select * from tblPaymentType", rsPaymentType)
            'MsgBox("Patient record is open")
        End If

        If Not (rsPaymentType.BOF And rsPaymentType.EOF) Then
            rsPaymentType.MoveFirst()
            Do
                If rsPaymentType("paymentType").Value = comPaymentType.Text Then
                    rData("paymentType").Value = rsPaymentType("paymentTypeID").Value
                    Exit Do
                Else
                    rData("paymentType").Value = 0
                End If
                rsPaymentType.MoveNext()
            Loop Until rsPaymentType.EOF

        End If

        rsData.Update()
    End Sub

Public Function h_N0_Generator(rs As ADODB.Recordset) As String

        Dim str, p1() As String
        Dim auto_long As Long
        Dim hMonth As String
        Dim strCounter As String, temp As String

        'this counter file is added to make the hNumber unique for multiple counter /* in the file counter number is added and have respective counter number only*/ 
        FileOpen(FileNum, "C048ounter.txt", OpenMode.Input)
        strCounter = LineInput(FileNum)
        FileClose(FileNum)
        If strCounter = "" Then
            strCounter = "1"
        End If

        hMonth = Month(Now).ToString("D2")


        If (rs.EOF And rs.BOF) Then
            h_N0_Generator = "NIRM-" & Year(Now) & "-" & hMonth & "-" & "00000" & strCounter
        Else

            rs.MoveLast()
            str = rs("HNumber").Value

            p1 = str.Split("-")
            ' check if the current month is the same as in last stored Hospital No or not 
            'if yes the last five digits increment otherwise it restarts with 0
            If p1(2) = Month(Now) And p1(1) = Year(Now) Then
                temp = Right(rs(0).Value, 6)
                auto_long = Left(temp, 5) + 1
                h_N0_Generator = "NIRM-" & Year(Now) & "-" & hMonth & "-" & Right("00000" & auto_long, 5) & strCounter
            Else
                h_N0_Generator = "NIRM-" & Year(Now) & "-" & hMonth & "-" & "00000" & strCounter
            End If
        End If
        'Return auto_num

    End Function

0 个答案:

没有答案