国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#中關于通過dataGrid更新數據庫

2024-07-21 02:22:50
字體:
來源:轉載
供稿:網友
各位大蝦好!我剛剛接觸c#.net學習不久,原來一直在用delphi做開發,突然轉型感覺甚是不爽,這兩天研究了一下如何通過datagrid更新數據庫記錄的問題,有點小收獲,在這里我把我的方法貼出來,供各位大蝦斧正!謝謝!
//*************************遍歷datagrid行更新數據******************************************
private void updatefromdatagrid()
{
string update_sql="";

//開始更新
system.data.sqlclient.sqlconnection conn_update=new sqlconnection();
conn_update.close();
conn_update.connectionstring=conntsql;
conn_update.open();

system.data.sqlclient.sqlcommand comm_update=new sqlcommand();
comm_update.connection=conn_update;

system.data.sqlclient.sqldataadapter da_update=new sqldataadapter();
da_update.updatecommand=comm_update;

//遍歷datagrid所有數據并修改
for(int i=0;i<=datagrid1.visiblerowcount-2;i++)
{
update_sql="update client_manage set client_name='"+datagrid1[i,1].tostring()+"',client_phone='"+datagrid1[i,2].tostring()+"',client_address='"+datagrid1[i,3].tostring()+"' where client_id="+datagrid1[i,0].tostring();
comm_update.commandtext=update_sql;
comm_update.executenonquery();
}

//關閉連接節約網絡資源
conn_update.close();
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肃南| 息烽县| 五河县| 太原市| 西充县| 台江县| 宜兰县| 定安县| 永德县| 宜阳县| 冕宁县| 广河县| 西贡区| 凉城县| 唐海县| 昭平县| 金溪县| 舒兰市| 申扎县| 乌兰县| 镇原县| 祁东县| 林周县| 南开区| 若尔盖县| 厦门市| 方山县| 钟祥市| 达孜县| 陕西省| 台北市| 电白县| 冕宁县| 宁乡县| 泾阳县| 洮南市| 樟树市| 都江堰市| 湄潭县| 临颍县| 鹤山市|