so above loop is working fine upto 1000 times.. after that it breakes, it shows strange behaviour, skipping some counts, repeating same count value, why it is?
can you guys help please how to avoid this
Rama-MCTS
The Path to Sucess is allways under construction
ramarao.mcts
Participant
857 Points
256 Posts
Strange Behaviour of For Loop
Oct 08, 2010 04:02 PM|LINK
Hi Friends,
I am getting Strange behaviour from the for loop.
Here is the loop
for(i=1, i<=1000000, i++)
{
label1.text = string1;( string 1, 2 , 3 comming from logic)
label2.text = string2;
label3.text = string3;
label4.text = string4;
once i got them i storing in the table of sql server using following steps,
SqlConnection conn = new SqlConnection();
conn.ConnectionString = " connectionstring ";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT INTO table(value1, value2, value3, value4, value5) VALUES( @i, @value1,@value2,@value3,@value4)";
cmd.Parameters.Add(new SqlParameter("@i", i ));
cmd.Parameters.Add(new SqlParameter("@value1", Label1.Text));
cmd.Parameters.Add(new SqlParameter("@value2", Label2.Text));
cmd.Parameters.Add(new SqlParameter("@value3", Label3.Text));
cmd.Parameters.Add(new SqlParameter("@value4", Label4.Text));
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
so above loop is working fine upto 1000 times.. after that it breakes, it shows strange behaviour, skipping some counts, repeating same count value, why it is?
can you guys help please how to avoid this
The Path to Sucess is allways under construction
Haitham Khed...
Participant
1232 Points
219 Posts
Re: Strange Behaviour of For Loop
Oct 08, 2010 04:52 PM|LINK
use SQL Bulk Insert instead :
Bulk Insert into SQL from C# App
https://blogs.msdn.com/b/nikhilsi/archive/2008/06/11/bulk-insert-into-sql-from-c-app.aspx