如何使用datagridview使用c#winform将多个项插入sql db [英] How to use a datagridview to insert multiple item to an sql db using c# winform

查看:65
本文介绍了如何使用datagridview使用c#winform将多个项插入sql db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我有一个带有两个文本框的表单和一个有两列的datagridview。现在我希望用户能够在datagridview中填写任意数量的数据,并在文本框中输入名称和年龄等信息,当他们点击保存时,信息以及datagridview信息应保存到sql server db中的一个表。即,一列中人员的姓名,另一列的年龄,以及同一行上一列的数据网格。不知道是否可能。但如果有更好的方法请建议。谢谢

Hi friends
i have a form with two textboxes and a datagridview that has two columns. Now i want users to be able to fill in as many data as they want into the datagridview, and also enter information such as name and age into the textboxes and when they click on save buton the information along with the datagridview informations should be saved to a table in the sql server db. I.e the name of the person to one column, the age to another column and the datagrid to one column on the same row. Dont know if is possible. But if there is a better way please suggest.thanks

推荐答案

使用两个参数名称和年龄制作一个插入语句函数

并使用表中的选择名称和年龄制作声明




第一个声明从文本框中获取数据



Make an insert statement function with two parameters name and age
and make statement with select name and age from table


1st statement take data from textbox

insertintotable(textbox1.text,textbox2.text);





和第二个语句从select语句的数据表中获取数据





and the 2nd statement take data from datatable of select statement

datatable dt=selectnameandage();





然后使用此...





then use this ...

datagridview.datasource=dt;





全部在保存按钮下



all of that under the save button


这篇关于如何使用datagridview使用c#winform将多个项插入sql db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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