Jump to content


C# and MySQL Problem

  • Please log in to reply
1 reply to this topic

#1 blishman

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 October 2006 - 03:32 PM

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

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 October 2006 - 05:47 PM

I'm not familiar with this wrapper class.. but it sounds like you're in the for loop too many times.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users