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