G
Guest
My debugger is saying that the ConnectionString property has not been
initialized. when I try to open the connection. My goal is to loop through an
arraylist of objects (OrderModel) and insert a record each time. What am I
missing here?
using (SqlConnection conn = new
SqlConnection(ConfigurationManager.AppSettings["myConnectionString"]))
{
int counter = 0;
SqlCommand cmd = conn.CreateCommand();
cmd.Connection.Open();
foreach (OrderModel ord in NewOrders)
{
cmd.CommandText = buildSql(ord);
try
{
cmd.ExecuteNonQuery();
counter++;
}
catch (SqlException ex)
{
TextBox1.Text = ex.Message;
}
}
TextBox1.Text = counter.ToString() + " records inserted";
}
initialized. when I try to open the connection. My goal is to loop through an
arraylist of objects (OrderModel) and insert a record each time. What am I
missing here?
using (SqlConnection conn = new
SqlConnection(ConfigurationManager.AppSettings["myConnectionString"]))
{
int counter = 0;
SqlCommand cmd = conn.CreateCommand();
cmd.Connection.Open();
foreach (OrderModel ord in NewOrders)
{
cmd.CommandText = buildSql(ord);
try
{
cmd.ExecuteNonQuery();
counter++;
}
catch (SqlException ex)
{
TextBox1.Text = ex.Message;
}
}
TextBox1.Text = counter.ToString() + " records inserted";
}