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. Posting an Unbound DataGridView to a MySQL Table

Posting an Unbound DataGridView to a MySQL Table

Scheduled Pinned Locked Moved C#
mysqltutorialcareer
6 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.
  • J Offline
    J Offline
    Jeff Patterson
    wrote on last edited by
    #1

    Hello all, I am a bit perplexed and maybe one of you can point me in the right direction. I have a windows form containing a DataGridView that has data imported into it from Excel and a combobox representing a job number. A user will make changes to the data in the DataGridView and then I want to post this entire DataGridView plus the job number to a MySQL table. I havne't found any information about how to post the unbound DataGridView to the MySQL table with one extra column of data (job number). What I would like to know is the proper steps to accomplish this task. I am using VS2008 and the MySQL Connector/NET v6.2.3 Thanks Jeff

    P 1 Reply Last reply
    0
    • J Jeff Patterson

      Hello all, I am a bit perplexed and maybe one of you can point me in the right direction. I have a windows form containing a DataGridView that has data imported into it from Excel and a combobox representing a job number. A user will make changes to the data in the DataGridView and then I want to post this entire DataGridView plus the job number to a MySQL table. I havne't found any information about how to post the unbound DataGridView to the MySQL table with one extra column of data (job number). What I would like to know is the proper steps to accomplish this task. I am using VS2008 and the MySQL Connector/NET v6.2.3 Thanks Jeff

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Assuming I have the data in a DataTable, I cobble up a (parameterized) INSERT statement based on the table name and column names then iterate through the Rows setting the parameter Values and calling ExecuteNonQuery. I have a routine that does it in one of my data access classes.

      J 1 Reply Last reply
      0
      • P PIEBALDconsult

        Assuming I have the data in a DataTable, I cobble up a (parameterized) INSERT statement based on the table name and column names then iterate through the Rows setting the parameter Values and calling ExecuteNonQuery. I have a routine that does it in one of my data access classes.

        J Offline
        J Offline
        Jeff Patterson
        wrote on last edited by
        #3

        Thanks for the response. That sounds simple enough, except that I don't know how to access each of the data rows when none are selected. All of the literature that I am looking at assumes that data in the datagridview was taken out of a database table and then updating is a snap. but... it seems strange to me that using a datagridview for data entry should be so hard. (I think I am overlooking something, but I don't know what it could be.) Unfortunately, I am very confused and don't really know where to proceed from here. Jeff

        L 1 Reply Last reply
        0
        • J Jeff Patterson

          Thanks for the response. That sounds simple enough, except that I don't know how to access each of the data rows when none are selected. All of the literature that I am looking at assumes that data in the datagridview was taken out of a database table and then updating is a snap. but... it seems strange to me that using a datagridview for data entry should be so hard. (I think I am overlooking something, but I don't know what it could be.) Unfortunately, I am very confused and don't really know where to proceed from here. Jeff

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

          As Piebald said:

          foreach(DataGridViewRow row in myDGV) {
          .. stuff column values in an INSERT statement
          .. execute it
          }

          :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          J 1 Reply Last reply
          0
          • L Luc Pattyn

            As Piebald said:

            foreach(DataGridViewRow row in myDGV) {
            .. stuff column values in an INSERT statement
            .. execute it
            }

            :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            J Offline
            J Offline
            Jeff Patterson
            wrote on last edited by
            #5

            Thank You! After some trial and error with syntax and the imported column names from excel it worked as advertised. You saved me a ton of time. Jeff

            L 1 Reply Last reply
            0
            • J Jeff Patterson

              Thank You! After some trial and error with syntax and the imported column names from excel it worked as advertised. You saved me a ton of time. Jeff

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

              you're welcome :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              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