Si vous déplacez votre boucle for, vous n'aurez pas à établir plusieurs connexions. Juste une modification rapide de votre bloc de code (en aucun cas tout à fait correct) :
string StrQuery;
try
{
using (SqlConnection conn = new SqlConnection(ConnString))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for(int i=0; i< dataGridView1.Rows.Count;i++)
{
StrQuery= @"INSERT INTO tableName VALUES ("
+ dataGridView1.Rows[i].Cells["ColumnName"].Text+", "
+ dataGridView1.Rows[i].Cells["ColumnName"].Text+");";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
}
}
}
En ce qui concerne l'exécution de plusieurs commandes SQL à la fois, veuillez consulter ce lien :Plusieurs instructions dans une seule SqlCommand