我想更新有关数据网格中人员的信息吗? [英] I want to update informations about persons in a datagrid?

查看:96
本文介绍了我想更新有关数据网格中人员的信息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

datagrid中列出的人员详细信息,所有信息均来自mysql.

我想单击一个按钮,所有人员信息都应一个接一个地更新.但这是行不通的.第一人称信息已成功更新,但第二人称信息无效,并显示连接打开错误.

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();
}

推荐答案

将连接移开并在循环外关闭.

但是,为什么您还是那样做呢?为什么不对所有人员ID提交一个查询,然后遍历整个查询?与db的连接更少,更少的(潜在)网络流量,更明显的代码...

SELECT ... FROM ... WHERE personid IN(一个",两个",三个" ...)
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"...)


这篇关于我想更新有关数据网格中人员的信息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆