How to cleanly update database from Datagridview?

Why doesn't my original database update when I edit the datagridview in VB 2008?

  • I had followed a tutorial on how to connect to an existing MS Access database using VB 2008. I was able to open the data source and drag the datagrid onto the form which created all the necessary adapters including the bindingsourcenavigator. In the tutorial with their existing tables, I was able to edit the datagridview on the form and click the "save" button on the navigator and see the records updated in the Access database. I created my own database and performed the same operations on my form and when I click save, the records do not update. This is the tutorial's code: Public Class Form1 --------------------------------------… Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ClassesTableAdapter.Fill(Me.StudentsD… Me.InstructorsTableAdapter.Fill(Me.Stude… End Sub --------------------------------------… Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click Me.InstructorsTableAdapter.Update(Me.Stu… End Sub --------------------------------------… End Class ______________________________________… This is my code from my project: Public Class Main --------------------------------------… Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEve… End Sub --------------------------------------… Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Fire_AttendanceTableAdapter.Fill(Me.F… EntryForm.Visible = False End Sub --------------------------------------… Private Sub btnAddEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddEntry.Click EntryForm.Focus() EntryForm.Visible = True End Sub --------------------------------------… Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Me.Fire_AttendanceTableAdapter.Update(Me… End Sub --------------------------------------… Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub --------------------------------------… Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Fire_AttendanceTableAdapter.Update(Me… End Sub --------------------------------------… Private Sub Fire_AttendanceBindingNavigatorSaveItem_… sender As System.Object, ByVal e As System.EventArgs) Handles Fire_AttendanceBindingNavigatorSaveItem.… Me.Validate() Me.Fire_AttendanceTableAdapter.Update(Me… Me.Fire_AttendanceBindingSource.EndEdit(… End Sub --------------------------------------… End Class ______________________________________… NOTE: I originally wanted to edit the database using an entry form in VB, but when that failed, I attempted to find the problem by trying to edit the table directly in the datagridview which led me to this current problem.

  • Answer:

    Assuming the code is the same between the example and your own DB, maybe it's a permissions issue involving the user and password in the connection string. Do you get any errors or warnings at all? I'm currently working on a project in Visual Basic which connects to a MySQL database. I found it easier (maybe that's just me) to form my own queries and execute them manually. Then the datagridview updates and my changes are saved.

Toad at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.