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. C#
  4. changes in a datagrid?

changes in a datagrid?

Scheduled Pinned Locked Moved C#
databasehelpcsssql-serversysadmin
10 Posts 2 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.
  • M Offline
    M Offline
    Manster
    wrote on last edited by
    #1

    Can anyone help me get my datagrid to update it's data? I’ve populated a datagrid with the contents of a table from an access database, but the problem I’m running into is when I change a value in the grid it’s not being saved/updated/deleted in the database. Has anyone ever done anything like this before? I've seen some examples in sql server and one or two things in access from the web but none of them seem to work correctly. ;P Thanks

    K 1 Reply Last reply
    0
    • M Manster

      Can anyone help me get my datagrid to update it's data? I’ve populated a datagrid with the contents of a table from an access database, but the problem I’m running into is when I change a value in the grid it’s not being saved/updated/deleted in the database. Has anyone ever done anything like this before? I've seen some examples in sql server and one or two things in access from the web but none of them seem to work correctly. ;P Thanks

      K Offline
      K Offline
      Kant
      wrote on last edited by
      #2

      Manster wrote: Can anyone help me get my datagrid to update it's data? Looks like nobody answered your earlier post. ;) Anyway I will try. Did you check the RowState property "DataRowState.Modified" value? Don't :beer: and drive.

      M 1 Reply Last reply
      0
      • K Kant

        Manster wrote: Can anyone help me get my datagrid to update it's data? Looks like nobody answered your earlier post. ;) Anyway I will try. Did you check the RowState property "DataRowState.Modified" value? Don't :beer: and drive.

        M Offline
        M Offline
        Manster
        wrote on last edited by
        #3

        I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.

        K 2 Replies Last reply
        0
        • M Manster

          I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.

          K Offline
          K Offline
          Kant
          wrote on last edited by
          #4

          Post your code snippet, so that others can identify the problem. Is the data grid on a WebForm or Windows Form? Don't :beer: and drive.

          M 1 Reply Last reply
          0
          • K Kant

            Post your code snippet, so that others can identify the problem. Is the data grid on a WebForm or Windows Form? Don't :beer: and drive.

            M Offline
            M Offline
            Manster
            wrote on last edited by
            #5

            My datagrid is on a windows form. This is the code that is in the m_DataGrid_Validate() grid event when you close the application once some data has been changed in the grid. DataSet dsUpdate = m_MyDataSet.GetChanges(); OleDBDataAdapter dataAdapter = new OleDBDataAdapter ("Update Authors set ...", m_sConn); OleDBCommandBuilder cb = new OleDBCommandBuilder(dataAdapter); dataAdapter.UpdateCommand = cb.GetUpdateCommand(); dataAdapter.Update(dsUpdate, "Authors"); dsUpdate.AcceptChanges();

            1 Reply Last reply
            0
            • M Manster

              I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.

              K Offline
              K Offline
              Kant
              wrote on last edited by
              #6

              Try this: change the button1 to your update button name dataSet21 to your DataSet name. oleDbDataAdapter1 to your DataAdapter name. Products to your table name. I used Northwind database via MSDE and it worked. private void button1_Click(object sender, System.EventArgs e) { if (dataSet21.HasChanges()) { try { int nModified; nModified = oleDbDataAdapter1.Update(dataSet21.Products); string strOutput; strOutput = "Modified " + nModified + " products(s)"; MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Update failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information); } } Don't :beer: and drive.

              M 1 Reply Last reply
              0
              • K Kant

                Try this: change the button1 to your update button name dataSet21 to your DataSet name. oleDbDataAdapter1 to your DataAdapter name. Products to your table name. I used Northwind database via MSDE and it worked. private void button1_Click(object sender, System.EventArgs e) { if (dataSet21.HasChanges()) { try { int nModified; nModified = oleDbDataAdapter1.Update(dataSet21.Products); string strOutput; strOutput = "Modified " + nModified + " products(s)"; MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Update failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information); } } Don't :beer: and drive.

                M Offline
                M Offline
                Manster
                wrote on last edited by
                #7

                I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it? Thanks for all your help!

                K 1 Reply Last reply
                0
                • M Manster

                  I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it? Thanks for all your help!

                  K Offline
                  K Offline
                  Kant
                  wrote on last edited by
                  #8

                  Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.

                  M 2 Replies Last reply
                  0
                  • K Kant

                    Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.

                    M Offline
                    M Offline
                    Manster
                    wrote on last edited by
                    #9

                    Yea I think that's it. I declared a dataset object in my code, I didn't add it to the form through the generate option. Hopefully that will do the trick. I haven't had a chance to test it yet. Thanks for all your help!:)

                    1 Reply Last reply
                    0
                    • K Kant

                      Manster wrote: I'm new to C# Me too. ;) Manster wrote: You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? Yep. Using "Data Adapter Configuration Wizard" (by dragging OleDbDataAdapter onto the form) Manster wrote: The dataSet21 dataset is the same one you used to populate the grid in the first place? Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset" Select "New" and select your table. Is that what you are looking for? or Am I mumbling something else? Don't :beer: and drive.

                      M Offline
                      M Offline
                      Manster
                      wrote on last edited by
                      #10

                      For some reason I can't get your changes to work. Is their any chance you can send me your demo project? Thanks :)

                      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