如何创建具有列和行的gridview [英] how to create gridview which has column and row

查看:68
本文介绍了如何创建具有列和行的gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在构建一个具有列和行以显示数据库数据的网格视图时遇到问题.是否可以构建它?我不知道该怎么做.VisualStudio中的模板只有一列.没有行.我可能已经尝试过了,但有时还是行不通.请帮助我如何构建它以及如何绑定它.

例如:Column0 Column1 Column2

第0行

第1行

第2行

请帮助我.谢谢.

Hi all,

im having a problem to build a gridview that has column and row that display data from database .is it possible to build it? i dont know how to do it.the template in visual studio only has the column.not the row.i already tried so may times but it didnt work.please help me on how to build it and also how to bind it.

eg: Column0 Column1 Column2

Row0

Row1

Row2

pls help me.thanks.

推荐答案

//create the connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";

//create the database query
string query = "SELECT * FROM MyTable";

//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);

//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);

//create a DataTable to hold the query results
DataTable dTable = new DataTable();

//fill the DataTable
dAdapter.Fill(dTable);

//the DataGridView
DataGridView dgView = new DataGridView();

//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();

//set the BindingSource DataSource
bSource.DataSource = dTable;

//set the DataGridView DataSource
dgView.DataSource = bSource;

dAdapter.Update(dTable);


您是否正在寻找诸如Pivot之类的东西?
参考: http://unboxedsolutions.com/sean/archive/2004/08/30/302. aspx [^ ]
Are you looking for something like Pivot by any chance?
Ref: http://unboxedsolutions.com/sean/archive/2004/08/30/302.aspx[^]


这篇关于如何创建具有列和行的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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