I am sure both of them would work. But I am wondering, should I keep the connection open till the datatable loop is done? Or open an connection and close it for each time of the loop to keep the connection short?
foreach (DataRow row in dt.Rows)
{
using(SqlConnection con = new SqlConnection(conString))
{
// do things
}
}
OR:
using(SqlConnection con = new SqlConnection(conString))
{
foreach (DataRow row in dt.Rows)
{
// do things
}
}