Well...it isn't going to compile. Or work if it did.
Let's have a look at your control structures:
try
{
for (int i = 0; i <= dataGridView2.Rows.Count-1; i++)
{
if (dr.Read())
{
}
else
{
}
else
{
}
}
}
}
catch (Exception ex)
{
}
finally
{
}
}
So, starting in the middle, you have this:
if (a) A;
else B;
else C;
What is that? you can't have two
else
clause for the same
if
! That's wrong, and I'm not sure what you are trying to do there...
Ignore that for a moment, (or assume you fixed it) and the
catch
doesn't match with the
try
- you have a spurious "}" in there.
Now let's look at what happens if (by a miracle) it did compile and work.
You open the connection in the loop. Why? You also close it in the loop. And in the
finally
block...
And whichever way you go in the
if
the result is the same:
return
or close the form completely!
Frankly, this looks like you randomly grabbed lines of code from the internet and through them together, hoping it would magically work. And when it didn't, stuffed it up here in the hope we would fix it for you.
Development doesn't work like that: it's one of the few subjects you can study at school where you have to think about what you are trying to do. In that, it's a great introduction to the real world - but if you don't start to think here, you don;t end up flipping burgers by the end of term. You do in the real world...:laugh: