Results 1 to 1 of 1

Thread: Missing Database Entries

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Missing Database Entries

    Hi guys, i have a bus ticketing application using windows mobile 6.0, framework 3.5 and SQL CE as Database.

    I recently encountered a problem. which is my database entry is lost upon accidental or manual reset (soft reset) of device. I am pretty sure that the Insert function is successful. But after the reset, the last entry of my database is gone.

    It seems like the last database records does not update. I dont know if its a delay or something.

    Here is my code :
    Code:
    Public Sub SaveData()
    
            Dim stSQL As String
    
            da = New clsDataAccess
            Try
                'TODO INSERT TO TICKETS
                stSQL = "INSERT INTO eBUS_TRANSACTIONS(" & _
                        "bundle_no," & _
                        "bus_no," & _
                        "plate_no," & _
                        "route," & _
                        "route_bound," & _
                        "trip_no," & _
                        "trip_date," & _
                        "km_run," & _
                        "km_from," & _
                        "place_from," & _
                        "km_to," & _
                        "place_to," & _
                        "amount," & _
                        "ticket_no," & _
                        "ticket_type," & _
                        "driver_name," & _
                        "conductor_name," & _
                        "timestamp)"
                stSQL = stSQL & " VALUES(" & _
                        Str2Fld(pstBundleNo) & "," & _
                        Str2Fld(pstBusNo) & "," & _
                        Str2Fld(pstPlateNo) & "," & _
                        Str2Fld(pstRoute) & "," & _
                        Str2Fld(pstRouteBound) & "," & _
                        Fld2Num(pstTripNo) & "," & _
                        Str2Fld(pstTripDate) & "," & _
                        Fld2Num(stKM) & "," & _
                        Fld2Num(btn_FM.Text) & "," & _
                        Str2Fld(lblFM.Text.Replace("Origin:", "")) & "," & _
                        Fld2Num(btn_TO.Text) & "," & _
                        Str2Fld(lblTO.Text.Replace("Destination:", "")) & "," & _
                        Fld2Dob(btnAmount.Text.Replace("Php", "")) & "," & _
                        Str2Fld(stTicketNo) & "," & _
                        Str2Fld(cboType.Text) & "," & _
                        Str2Fld(pstDriverName) & "," & _
                        Str2Fld(pstConductorName) & "," & _
                        Str2Fld(Now) & ")"
                da.InsertData(stSQL)
    
                stSQL = "UPDATE eBUS_SETTINGS SET last_ticket=last_ticket + 1"
                da.UpdateData(stSQL)
    
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical, stCaption)
            Finally
                da.Dispose()
                BackupData(False)
            End Try
    
        End Sub
    Code:
      Public Sub InsertData(ByVal stQuery As String)
            Try
                cmd = New SqlCeCommand
                cmd.Connection = gCN
                cmd.CommandText = stQuery
                cmd.ExecuteNonQuery()
                cmd.Dispose()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub
    but if i inserted this line of code at the end of my save data everything works fine.
    Code:
     gCN.Close()
     If gCN.State = ConnectionState.Closed Then gCN.Open()
    Last edited by rothj0hn; May 27th, 2014 at 01:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width