Jump to content


This topic is now archived and is closed to further replies.


C# and MySQL Problem

Recommended Posts

Ok so here is whats happening: my job is to take a MySQL database and update it regularly using c#...the problem comes when I have to insert new rows to the table.  Using the OdbcDataAdapter, i build the mySQL data into a table, run the update algorithm, which in the current case adds 72 rows to it.  I then try to update it back in by building the insert commands one at a time to add the new rows into the mySQL table, but the problem is that for each time i call the adapter.Update() function, it inserts 72 rows using the value i specify...so that the table looks like this:

newcomp1    value  value  value
newcomp1    value  value  value
... (70 more times)
newcomp2    value  value  value
newcomp2    value  value  value

here is the code for that portion:

complete is the final dataset that contains the machines table's update
machines not used in the complete.tables context is the name of the table on the mysql server
adapter is the OdbcDataAdapter
max2 is the size of the original table
max is the size of the updated table

            for (int j = max2; j < max; j++) {
                String InsertString = "INSERT INTO machines (machine_name, boot_os, harddrive_size, ram_size, proc_speed) VALUES";
                InsertString += "(\"" + complete.Tables["machines"].Rows[j]["machine_name"].ToString() + "\",\"" + complete.Tables["machines"].Rows[j]["boot_os"].ToString() + "\"," +
                    complete.Tables["machines"].Rows[j]["harddrive_size"].ToString() + "," + complete.Tables["machines"].Rows[j]["ram_size"].ToString() + "," +
                      complete.Tables["machines"].Rows[j]["proc_speed"].ToString() + ");";
                OdbcCommand insrt = new OdbcCommand(InsertString, test_connection);
                adapter.InsertCommand = insrt;
                adapter.Update(complete, "machines");

any advice would be greatly appreciated, my email is blishman@fit.edu or my msn messenger is ishma_2002@hotmail.com

Share this post

Link to post
Share on other sites
I'm not familiar with this wrapper class.. but it sounds like you're in the for loop too many times.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.