Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
persons details listed in datagrid and all information comes from mysql.

I want to click a button and all person information should update by one by one. But it doesn't work. 1st person's information is updated successfully but from 2nd person it doesn't work and gives connection open error.

j=2;
row = grid1.Rows - 1;
for(i=1;i<row;i++)>
{
string id=grid1.cells(i,j).text;//this text contains person id

connection.open();
write sql query
..............
..............
..........where personid=id
connection.close();
}
Posted
Updated 31-May-10 23:51pm
v5

1 solution

Move the connection open and close outside the loop.

But why are you doing it that way anyway? Why not submit a single query for all person ids, and loop through that? Fewer connections to db, less (potential) network traffic, more obvious code...

SELECT ... FROM ... WHERE personid IN ("one", "two", "three"...)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900