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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Have a writable datagrid using an mdb

Have a writable datagrid using an mdb

Scheduled Pinned Locked Moved C#
databasecsshelpquestionannouncement
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.
  • G Offline
    G Offline
    Gian
    wrote on last edited by
    #1

    Hello, i'm trying to connect a DataGrid with a query that read a table of an MDB Access database. I've used OleDbConnection, OleDbDataAdapter and DataSet to access via the OLEDB 4.0 Provider the file. After that i can see the records. The code, used in Form Load is: connection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Temp\\Brick1.MDB"); dataadapter1 = new OleDbDataAdapter("SELECT * FROM [Articles];", connection1); dataset1 = new DataSet("DataSetTest"); dataadapter1.Fill(dataset1, "articles"); dataGrid1.DataSource = dataset1.Tables["articles"]; The problem is that if i change some cell value, than i close the window and reopen, i cant see any change of mine. Is there a simple way to update the data at every cell change or when selection is moved on a new row? i cant see any update events on the DataGrid component. I've searched for tutorials about this but i cant find anything about "forcing data update" from the grid.

    M H 2 Replies Last reply
    0
    • G Gian

      Hello, i'm trying to connect a DataGrid with a query that read a table of an MDB Access database. I've used OleDbConnection, OleDbDataAdapter and DataSet to access via the OLEDB 4.0 Provider the file. After that i can see the records. The code, used in Form Load is: connection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Temp\\Brick1.MDB"); dataadapter1 = new OleDbDataAdapter("SELECT * FROM [Articles];", connection1); dataset1 = new DataSet("DataSetTest"); dataadapter1.Fill(dataset1, "articles"); dataGrid1.DataSource = dataset1.Tables["articles"]; The problem is that if i change some cell value, than i close the window and reopen, i cant see any change of mine. Is there a simple way to update the data at every cell change or when selection is moved on a new row? i cant see any update events on the DataGrid component. I've searched for tutorials about this but i cant find anything about "forcing data update" from the grid.

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      Gian wrote: there a simple way to update the data at every cell change or when selection is moved on a new row? i cant see any update events on the DataGrid component. CurrenCellChaneged event. Mazy "I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein

      1 Reply Last reply
      0
      • G Gian

        Hello, i'm trying to connect a DataGrid with a query that read a table of an MDB Access database. I've used OleDbConnection, OleDbDataAdapter and DataSet to access via the OLEDB 4.0 Provider the file. After that i can see the records. The code, used in Form Load is: connection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Temp\\Brick1.MDB"); dataadapter1 = new OleDbDataAdapter("SELECT * FROM [Articles];", connection1); dataset1 = new DataSet("DataSetTest"); dataadapter1.Fill(dataset1, "articles"); dataGrid1.DataSource = dataset1.Tables["articles"]; The problem is that if i change some cell value, than i close the window and reopen, i cant see any change of mine. Is there a simple way to update the data at every cell change or when selection is moved on a new row? i cant see any update events on the DataGrid component. I've searched for tutorials about this but i cant find anything about "forcing data update" from the grid.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        The DataGrid is only a view on the data. The CurrentCellChanged event isn't really the place to update the database with your changes, which you must do manually. Changing values in the DataGrid will change your DataSet, but you must update the database with those changes using OleDbDataAdapter.Update, which requires that you assign the necessary properties like InsertCommand, UpdateCommand, and DeleteCommand, besides the required SelectCommand. If you don't update the database, then when you re-get your DataSet it won't have any changes. This is not automatic. Again, the CurrentCellChanged is fired too often and should not be used to update your database. Instead, do that when the form is closed or use a button who's Click event handler updates the database. See the OleDbDataAdapter class documentation for more information.

        Microsoft MVP, Visual C# My Articles

        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