如何使用datagridview在sql server中插入数据并将数据更新到表中? [英] How to insert,update data to table in sql server using datagridview?

查看:130
本文介绍了如何使用datagridview在sql server中插入数据并将数据更新到表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有访客
我在SQL Server 2008中有1个表(salesdetail)
在此表中,我有3个字段(代码,项目代码,数量)
在vb.net中,我创建一个表单并将DataGridView放到该表单上
我还在DataGridView(Itemcode,IteamName,Qty,price,Total)上设置了5列
我使用这样的sql语句(从itemcode ="& txtitemcode.text&""的项目中选择itemcode,itemanem,price)
我使用此查询将项目信息显示到我的gridview.
当我在gridview中输入3个项目时,我想将gridView中的所有项目保存到我的表中(salesorder)
注意
我只想将代码,商品代码,数量保存到我的销售明细中,以用于商品名称,价格,全部用于显示.

请帮我如何将数据从gridView保存到表中?

最好的问候,
TONY

解决方案

您可以使用 http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx [^ ]

另一个注意事项:不要在您的SQL语句中连接文字(从itemcode = ''& txtitemcode.text&''"的项目中选择项目代码,项目名称,价格).而是使用参数.详细信息: SqlParameter [
i use this query to display the item information to my gridview.
when i input 3 items on gridview, i want to save all item in gridView to my table(salesorder)
Note
i want to save only code,itemcode,qty to my salesdetail, for itemname,price,total use for display only.

Please help me how i can save data from gridView to my table?

Best Regards,
TONY

解决方案

You can use SqlDataAdapter[^] to reflect changes in the datagridview (or actually in the datatable) to the database.

For example see: http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx[^]

Another note: Don''t concatenate literals in your SQL statements ("select itemcode,itemanem,price from item where itemcode='' & txtitemcode.text & "''""). Instead use parameters. More info: SqlParameter [^]


这篇关于如何使用datagridview在sql server中插入数据并将数据更新到表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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