I'm trying to insert few rows at one time to the MySql database. When I do it over localhost
it works well. But when I run it connecting my pc and server to the for example mobile network, it doesn't insert anything to the table. Same for my home network.
This is how I insert data:
void importData()
{
using (MySqlConnection conn = new MySqlConnection(constring))
{
string data = null;
conn.Open();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null)
{
data = dataGridView1.Rows[i].Cells[0].Value.ToString();
}
else
{
break;
}
string query = "ALTER TABLE zlecenia_dzis DROP id_zlecenia;ALTER TABLE zlecenia_dzis ADD id_zlecenia int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
INSERT INTO zlecenia_dzis(numer_zlecenia, data_zlecenia, model) SELECT * FROM (SELECT '" + dataGridView1.Rows[i].Cells[1].Value + "',
STR_TO_DATE('" + data + "', '%d.%m.%Y'), '" + dataGridView1.Rows[i].Cells[2].Value + "') AS tmp WHERE NOT EXISTS( SELECT numer_zlecenia
FROM zlecenia_dzis WHERE numer_zlecenia='" + dataGridView1.Rows[i].Cells[1].Value + "')LIMIT 1;";
using (MySqlCommand cmd = new MySqlCommand(query, conn))
{
cmd.ExecuteNonQuery();
}
}
conn.Close();
}
}
question from:
https://stackoverflow.com/questions/66046017/cannot-insert-more-than-one-row-into-mysql-database 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…