r/visualbasic • • May 20 '20

Urgent saving data into access issue

8 Upvotes

16 comments sorted by

2

u/stapper May 20 '20

Don't you need to commit your changes before closing?

3

u/bouoron May 20 '20

Dim cb As New OleDb.OleDbCommandBuilder(da)

Dim dsNewRow As DataRow

dsNewRow = ds.Tables("CustomerList").NewRow()

dsNewRow.Item(0) = txtCustomerID.Text

dsNewRow.Item(1) = txtCustomerName.Text

dsNewRow.Item(2) = cboGender.Text

dsNewRow.Item(3) = txtAddress.Text

dsNewRow.Item(4) = txtContactNumber.Text

ds.Tables("CustomerList").Rows.Add(dsNewRow)

da.Update(ds, "CustomerList")

totalrecords = totalrecords + 1

MsgBox("Registered")

→ More replies (1)

2

u/teamhog May 20 '20

That’s my thoughts.
OP needs to do something along the line of:

 Private Sub Form_BeforeUpdate(Cancel As Integer)
 
  ' This procedure checks to see if the data on the form has
  ' changed. If the data has changed, the procedure prompts the
   ' user to continue with the save operation or to cancel it. Then
  ' the action that triggered the BeforeUpdate event is completed.

  Dim ctl As Control
 
  On Error GoTo Err_BeforeUpdate

   ' The Dirty property is True if the record has been changed.
  If Me.Dirty Then
    ' Prompt to confirm the save operation.
    If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
            "Save Record") = vbNo Then
       Me.Undo
    End If
  End If
 
 Exit_BeforeUpdate:
  Exit Sub
 
 Err_BeforeUpdate:
  MsgBox Err.Number & " " & Err.Description
  Resume Exit_BeforeUpdate
 End Sub

1

u/RJohn12 May 20 '20

I'm just making best guesses, do you need to manually close your access connection on close? Does your app include any code for deleting records?

2

u/bouoron May 20 '20

the connection closed base on the code and I don't have any code that deleted the record

1

u/RJohn12 May 20 '20

any code for deleting ANY records?

2

u/bouoron May 20 '20

nope

2

u/RJohn12 May 20 '20

the clue is that whatever happens is happening when the app starts, so I'd start looking there

can you manually add records to the table in access? Do they stay there?

1

u/bouoron May 20 '20

manually add makes it stay there

→ More replies (1)

2

u/tommax007 May 20 '20

It looks like every time you build the project, access file is copied from your project folder to the debug folder.

1

u/10kKarmaForNoReason May 20 '20

What wallpaper is that and how is animated

1

u/DrEagleTalon May 20 '20

This is the only thing I want to know

1

u/URIXMX May 20 '20

Necesitas que la base de datos se duplique en tu proyecto para que pueda aplicarse los cambios en tu base de datos en tiempo real

1

u/CharlieMay VB.Net Intermediate May 20 '20

it appears you're running a local instance. If so, click on the database file in solution explorer and select CopyToOutPutDirectory property set it to never copy.