I have a big updated list of strings which must be uploaded with update of each row from 0 to last index by rewriting of exist records and adding of new rows to MySql database on remote server each time user calls function.
The adding of data string by string takes a lot of time even if not hangs by process:
foreach (string str in myList)
{
string Query = "insert into tab(a) values(@a);";
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand conn_ = new MySqlCommand(Query, conn);
conn.Open();
conn_.ExecuteNonQuery();
conn.Close();
}
My goal is to figure out, what should be most proper way to do this fast. Maybe I should create and update table locally and then somehow upload it to database.
I have a List<string> myList = new List<string>(); which contains about 5000 rows and I have table in database on remote server:
id | user | nickname
_____________________
0 | record | record
1 | ... | ...
My desired result is to update all records from 0 to highest index with adding of new records and removing of extra records in case if current upload contains less records then previous each time from 0 index, of course no maters if index will come with gap between removed rows.
Rows.Add(string.Format("('{0}','{1}')", MySqlHelper.EscapeString(str));This line has issues. You need two values on the right side to fill{0}and{1}. To test, change it toRows.Add(string.Format("('{0}','{1}')", MySqlHelper.EscapeString(str),MySqlHelper.EscapeString(str));to see if your code works.userandnicknameand it is not the reason of exception, also solution does not contains update method described above. So, I'm not sure about thissCommand.toString()to analyze the SQL. Copy and paste the generated SQL in a mySQL editor such as SQLyog and it will highlight where there issue is in SQL.sCommand.ToString()looks like this: INSERT INTO tab (user, nickname) VALUES('tom','xiu787?. tom45. tomtom?. ttt000.'),('sally','sally90. sal90?. sal900. sallysally90?. sallyo90.') this example shows only 2 rows, each one contains user and username(s) data included inside parentheses, separated by apostrophes and comma between user and usernames and separate rows