Hi there, I've restructured your code as much as possible even though the logic you've used, does not make ANY sense :S Anyways, you ought learn so many basic level coding 'stuff' like condition checking, try catch blocks, managing db connections, commenting, variable naming conventions, string manipulation, etc.
Take it slow and one by one; but learn them all.
I hope the restructuring helps the performance. If you explain what you really want to do, it would make it a lot easier to help you out.
Hope this helps, Regards
int i = 0;
if ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
{
for (int counter = 0; counter < ds.Tables[0].Rows.Count; counter++)
{
DataRow currentRow = ds.Tables[0].Rows[counter];
try
{
int digit = (int) currentRow["digit"];
int div = digit/i;
}
catch
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "UPDATE [mytb] SET [check]=0 WHERE [id] = @id";
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@id", currentRow["digit"]);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch
{
if (con.State != ConnectionState.Closed)
con.Close();
}
}
Label1.Text += string.Format("{0}, ", currentRow["id"].ToString());
}
}