take a look at the below while loop.
SqlDataReader dr;
while (dr.Read())
{
Response.Write("insert into test values(N'"+dr[0]+"', N'"+dr[1]+"'),<br>");
}
I am just printing something with a comma at the end (before that
). But For the last time when it gets printed, i dont want that comma.
How to find out that this loop is executing for the last time? so that i can avoid this comma getting printed by modifying it.
In general, it’s not really possible no know if you are on a last iteration of a while loop.
You could use a loop-and-a-half, where not the last, but the first run of the loop is different, like this:
However, it would be better to just use a
StringBuilderto construct the string in memory, and thenResponse.Writeit all at once, like this: