如果列数未知,则将DataGridView列数据插入数据库 [英] insert DataGridView columns data to database if number of Columns are unknown

查看:155
本文介绍了如果列数未知,则将DataGridView列数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含这些列的表:

id
学生证
subjectid1
标记1
subjectid2
标记2
........
subjectid10
标记10
总计

我有一个像这样的网格:

学生编号subjectid1 subjectid2 subjectid1总计
1 54(商标)74(商标)128

我想将此记录插入数据库.我不知道主题数(dgv中的列数)

I have a table with these columns:

id
Studentid
subjectid1
marks1
subjectid2
marks2
........
subjectid10
marks10
Total

I have a grid like this:

studentid subjectid1 subjectid2 subjectid1 Total
1 54(Marks) 74(Marks) 128

I want to insert this records, into database. I don''t [know] number of subjects (number of columns in dgv)

Thanks in advance.

推荐答案

int DataGridView.ColumnCount获取或设置DataGridView中显示的列数.

int DataGridView.ColumnCount Gets or sets the number of columns displayed in the DataGridView.

int count = myGridView.ColumnCount;




http://msdn.microsoft.com /en-us/library/system.windows.forms.datagridview.columncount(v=vs.80).aspx [




http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columncount(v=vs.80).aspx[^]


然后您无需设置gridview的设计,只需放置一个gridview并进行查询,并在侧面查询中放置所有别名并直接写

gridview1.datasource = ds.table [0];
gridview1.databind();


我从您的问题中了解到的信息可能会对您有所帮助.
Then You don''t set the design of gridview just put a gridview and make queried and in side queries put all alies name and direct write

gridview1.datasource=ds.table[0];
gridview1.databind();


What I have understand from your question this may help you..


这篇关于如果列数未知,则将DataGridView列数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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