推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 你问我答 查看内容

蒋怡:vb.net 怎么写入数据库数据

2020-8-11 18:16| 发布者: admin| 查看: 73| 评论: 0

摘要: 黎娟的回答: 使用.net下的system.sql.sqlclint类库下的sqlconnent;sqlcommand类进行写入操作 别说话我烦的回答: private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles ...

黎娟的回答:

使用.net下的system.sql.sqlclint类库下的sqlconnent;sqlcommand类进行写入操作

别说话我烦的回答:

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click dim sqlstr as string = "insert into tb values(" dim i as integer for i = 0 to datagridview1.columns.count - 1 sqlstr &= "'" & datagridview1.rows(datagridview1.rows.count - 1).cells(i) & "'" if i < datagridview1.columns.count - 1 then sqlstr &= "," next sqlstr &= ")" dim con as new sqlconnection(connectionstring) '这个自己写去 con.open() dim cmd as new sqlcommand(sqlstr, con) try dim result as integer = cmd.executenonquery() if result > 0 then msgbox "添加数据成功" else msgbox "添加数据失败" end if catch (ex as exception) msgbox "添加数据过程发生异常,原因:" & ex.message end try end sub


鲜花

握手

雷人

路过

鸡蛋

最新评论

热门推荐
最新资讯

广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

GMT+8, 2025-5-1 09:00 , Processed in 0.058350 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部