Jump to content

C# and MySQL Problem


blishman

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.