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. Updating changings back to DB from DataGridView

Updating changings back to DB from DataGridView

Scheduled Pinned Locked Moved C#
database
7 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.
  • W Offline
    W Offline
    WinSolution
    wrote on last edited by
    #1

    Dear All I want to updated the changes made in DataGridView back to SQL Table in an easiest way while i am working with 3-Tire approach (GUI, BusinessLogic, DataAccess) I have search a lot on Google but i am not able to find a good,simple and easy solution. Thanks for helping.

    H L 2 Replies Last reply
    0
    • W WinSolution

      Dear All I want to updated the changes made in DataGridView back to SQL Table in an easiest way while i am working with 3-Tire approach (GUI, BusinessLogic, DataAccess) I have search a lot on Google but i am not able to find a good,simple and easy solution. Thanks for helping.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Try looking at this[^], it might help.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • W WinSolution

        Dear All I want to updated the changes made in DataGridView back to SQL Table in an easiest way while i am working with 3-Tire approach (GUI, BusinessLogic, DataAccess) I have search a lot on Google but i am not able to find a good,simple and easy solution. Thanks for helping.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi , if you want to save datagrid back to SQL database then there is a very simple rules : - every table must have PK ( Exception will rise if don't )

                ds = new DataSet("tb");
                
                clsConnect.SqlDa = new SqlDataAdapter("SELECT \* FROM tb1 WHERE ID = 2", clsConnect.SqlCon);
        
                clsConnect.SqlCmdBuild = new SqlCommandBuilder(clsConnect.SqlDa);
                
                clsConnect.SqlDa.InsertCommand = clsConnect.SqlCmdBuild.GetInsertCommand();
                clsConnect.SqlDa.DeleteCommand = clsConnect.SqlCmdBuild.GetDeleteCommand();
                clsConnect.SqlDa.UpdateCommand = clsConnect.SqlCmdBuild.GetUpdateCommand();
        
                clsConnect.SqlDa.Fill(ds , "tb");
                dataGridView1.DataSource = ds.Tables\[0\];
                clsConnect.SqlDa.Update(ds.Tables\[0\]);
                ds.Tables\[0\].AcceptChanges();
        

        I know nothing , I know nothing ...

        H W 2 Replies Last reply
        0
        • L Lost User

          Hi , if you want to save datagrid back to SQL database then there is a very simple rules : - every table must have PK ( Exception will rise if don't )

                  ds = new DataSet("tb");
                  
                  clsConnect.SqlDa = new SqlDataAdapter("SELECT \* FROM tb1 WHERE ID = 2", clsConnect.SqlCon);
          
                  clsConnect.SqlCmdBuild = new SqlCommandBuilder(clsConnect.SqlDa);
                  
                  clsConnect.SqlDa.InsertCommand = clsConnect.SqlCmdBuild.GetInsertCommand();
                  clsConnect.SqlDa.DeleteCommand = clsConnect.SqlCmdBuild.GetDeleteCommand();
                  clsConnect.SqlDa.UpdateCommand = clsConnect.SqlCmdBuild.GetUpdateCommand();
          
                  clsConnect.SqlDa.Fill(ds , "tb");
                  dataGridView1.DataSource = ds.Tables\[0\];
                  clsConnect.SqlDa.Update(ds.Tables\[0\]);
                  ds.Tables\[0\].AcceptChanges();
          

          I know nothing , I know nothing ...

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          Hi Stark DaFixzer, Just posting to say I like the image in your user profile. Cute!

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          L 1 Reply Last reply
          0
          • H Henry Minute

            Hi Stark DaFixzer, Just posting to say I like the image in your user profile. Cute!

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thank you , this picture is "Baby Tux" .. linux stuff here is a big one , you can have it ... Click Here please

            I know nothing , I know nothing ...

            1 Reply Last reply
            0
            • L Lost User

              Hi , if you want to save datagrid back to SQL database then there is a very simple rules : - every table must have PK ( Exception will rise if don't )

                      ds = new DataSet("tb");
                      
                      clsConnect.SqlDa = new SqlDataAdapter("SELECT \* FROM tb1 WHERE ID = 2", clsConnect.SqlCon);
              
                      clsConnect.SqlCmdBuild = new SqlCommandBuilder(clsConnect.SqlDa);
                      
                      clsConnect.SqlDa.InsertCommand = clsConnect.SqlCmdBuild.GetInsertCommand();
                      clsConnect.SqlDa.DeleteCommand = clsConnect.SqlCmdBuild.GetDeleteCommand();
                      clsConnect.SqlDa.UpdateCommand = clsConnect.SqlCmdBuild.GetUpdateCommand();
              
                      clsConnect.SqlDa.Fill(ds , "tb");
                      dataGridView1.DataSource = ds.Tables\[0\];
                      clsConnect.SqlDa.Update(ds.Tables\[0\]);
                      ds.Tables\[0\].AcceptChanges();
              

              I know nothing , I know nothing ...

              W Offline
              W Offline
              WinSolution
              wrote on last edited by
              #6

              Thanks But i need an example that is based on 3-Tire Architecture.(GUI, BusinessLogic, DataAccess) i have tried such code with 3-Tire Arch. but it cause an error like "DataTable already belongs to another DataSet".

              L 1 Reply Last reply
              0
              • W WinSolution

                Thanks But i need an example that is based on 3-Tire Architecture.(GUI, BusinessLogic, DataAccess) i have tried such code with 3-Tire Arch. but it cause an error like "DataTable already belongs to another DataSet".

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I am sorry this beyond my knowledge ... :( forgive me ... :rose:

                I know nothing , I know nothing ...

                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