I need some tips on how to do this better, I am inserting multiple queries with using one connection.
I understand this is not good programming, especi
You should parameterized your query - ALWAYS, but for now you can concatenate those queries with ;
and then execute them once like:
string allQueries = string.join(';', query2, query3, query4, query5);
command.CommandText = allQueries;
int c = command.ExecuteNonQuery();
Currently you are just executing one query. Semicolon ;
marks end of statement in SQL, so combining these statements with ;
will make them separate statements but they will be executed under one execution.
kcray - This is what worked for me.
string[] arr = { query2, query3 };
string allQueries = string.Join(";", arr);
command.CommandText = allQueries;
int c = command.ExecuteNonQuery();