Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Save changes to database after loading .

Save changes to database after loading .

Scheduled Pinned Locked Moved Visual Basic
helpdatabasequestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KOKEMO
    wrote on last edited by
    #1

    My problem is that in the program that I am writing I cannot save the changes to database after I load the tables from it. Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & _ " DATA SOURCE = megas.mdb" Dim sqlstr As String = " select * from megas " Dim dtb As New DataTable ‘-------------------------------------------------------------- Private Sub btnload_Click(…) Handles btnload.Click dtb.Clear() Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) dataadapter.Fill(dtb) dataadapter.Dispose() dgdisplay1.DataSource = dtb End Sub ‘----------------------------------------------------------------- Private Sub btnsave_Click (…) Handles btnsave.Click Dim changes As Integer Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataadapter) changes = dataadapter.Update(dtb) dataadapter.Dispose() If changes > 0 Then MsgBox("SAVED ") Else MsgBox("not saved") End If End Sub I load the table form the database and nothing goes wrong with this part, but when I want to save the changes and I click the save btn , that is what I get “An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll “ What am I doing wrong? And why should I be getting this? Thank you. • Thanks for the previous help from Dave Kreskowiak and Naji Kotob +mackay, it really helped, especially that article. |-|■~F~|-|■

    C L 2 Replies Last reply
    0
    • K KOKEMO

      My problem is that in the program that I am writing I cannot save the changes to database after I load the tables from it. Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & _ " DATA SOURCE = megas.mdb" Dim sqlstr As String = " select * from megas " Dim dtb As New DataTable ‘-------------------------------------------------------------- Private Sub btnload_Click(…) Handles btnload.Click dtb.Clear() Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) dataadapter.Fill(dtb) dataadapter.Dispose() dgdisplay1.DataSource = dtb End Sub ‘----------------------------------------------------------------- Private Sub btnsave_Click (…) Handles btnsave.Click Dim changes As Integer Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataadapter) changes = dataadapter.Update(dtb) dataadapter.Dispose() If changes > 0 Then MsgBox("SAVED ") Else MsgBox("not saved") End If End Sub I load the table form the database and nothing goes wrong with this part, but when I want to save the changes and I click the save btn , that is what I get “An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll “ What am I doing wrong? And why should I be getting this? Thank you. • Thanks for the previous help from Dave Kreskowiak and Naji Kotob +mackay, it really helped, especially that article. |-|■~F~|-|■

      C Offline
      C Offline
      cutequencher
      wrote on last edited by
      #2

      The OleDb.OleDbException class is created whenever the .NET Framework Data Provider for OLE DB encounters an error generated from the server. (Client side errors are thrown as standard common language runtime exceptions.) OleDbException always contains at least one instance of OleDbError. -an explanation from msdn --the most common cause of this is because of a missing data source as what is written on your code: Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & _ " DATA SOURCE = megas.mdb" the "DATA SOURCE" should be replaced by "DataSource"(no spaces) and make sure that megas.mdb is properly installed on the odbc connection.

      1 Reply Last reply
      0
      • K KOKEMO

        My problem is that in the program that I am writing I cannot save the changes to database after I load the tables from it. Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & _ " DATA SOURCE = megas.mdb" Dim sqlstr As String = " select * from megas " Dim dtb As New DataTable ‘-------------------------------------------------------------- Private Sub btnload_Click(…) Handles btnload.Click dtb.Clear() Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) dataadapter.Fill(dtb) dataadapter.Dispose() dgdisplay1.DataSource = dtb End Sub ‘----------------------------------------------------------------- Private Sub btnsave_Click (…) Handles btnsave.Click Dim changes As Integer Dim dataadapter As New OleDb.OleDbDataAdapter(sqlstr, connstr) Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataadapter) changes = dataadapter.Update(dtb) dataadapter.Dispose() If changes > 0 Then MsgBox("SAVED ") Else MsgBox("not saved") End If End Sub I load the table form the database and nothing goes wrong with this part, but when I want to save the changes and I click the save btn , that is what I get “An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll “ What am I doing wrong? And why should I be getting this? Thank you. • Thanks for the previous help from Dave Kreskowiak and Naji Kotob +mackay, it really helped, especially that article. |-|■~F~|-|■

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, general exceptions (I guess OleDbException qualifies) often contain an "internal exception". You wont see it if you just look at Exception.Message, but you would see it when looking at Exception.ToString() so I recommend everyone to always log or display Exception.ToString(); it is longer by the fact that it provides more information. I am not sure but expect this to apply to your situation too. :)

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups