question

PIOTRDROZD-9291 avatar image
0 Votes"
PIOTRDROZD-9291 asked NavtejSaini-MSFT commented

Error when saving a record to database

I'm trying to create a save button in the form to save changes to a record made by the user.
When I run the code I get the error message unable to save to the database.
In the form the records are displayed in a data grid and then each record is displayed in text boxes.
After trying to save I get a red dot in the datagrid which says incorrect syntax near ','.
Here is the code that I'm using



  Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
    
     Try
         Dim result As New DialogResult()
         result = MessageBox.Show("Do you really want to save the record?", "Save Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
         If result = DialogResult.Yes Then
    
             Me.Validate()
             Me.CustomerRequestsBindingSource.EndEdit()
             Me.CustomerRequestsTableAdapter.Update(Me.AzureDataSet.CustomerRequests)
    
             MessageBox.Show("Record has been saved successfully", "Save Data", MessageBoxButtons.OK,
                MessageBoxIcon.Information)
    
             Me.CustomerRequestsTableAdapter.Fill(Me.AzureDataSet.CustomerRequests)
    
         Else
             Return
         End If
    
     Catch ex As Exception
         MessageBox.Show("Unable to save to database", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
     End Try
    
 End Sub


azure-sql-databasedotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The exception details will provide more information as to the cause of the error. In debug mode, set a break point in the catch block and examine the Exception object.

1 Vote 1 ·

1 Answer

PIOTRDROZD-9291 avatar image
0 Votes"
PIOTRDROZD-9291 answered NavtejSaini-MSFT commented

Thank you. I got to the bottom of this, turns out the table adapter was not configured for UPDATE. All working fine now :)

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@PIOTRDROZD-9291 Happy that you were able to resolve this and thank you for posting the resolution.

Regards
Navtej S

1 Vote 1 ·