如何使用DataView创建一个DataTable并用数据库中的数据填充它? [英] How to create a DataTable and filling it with a data from the database using the DataView?
问题描述
大家好,
我是ASP.NET的新开发人员,我想以编程方式使用HtmlTable或DataTable创建一个表,然后使用DataView使用数据库中的数据填充该表.
我可以使用HtmlTable创建表,但是当我搜索如何使用DataView用数据填充HtmlTable"时,我发现DataView无法与HtmlTable一起使用.所以我重复使用DataTable创建表,但是现在我需要使用DataView用数据填充它,那么我该怎么做呢?
我的代码:
Hello everybody,
I am a new ASP.NET developer and I want to create a table programmatically using HtmlTable or DataTable and then filling this table with the data from the database using DataView.
I could be able to create a table using HtmlTable but when I did a search regarding "how to fill HtmlTable with a data using DataView", I found that DataView will not work with HtmlTable. So I repeated creating the table using the DataTable, but now I need to fill it with the data using DataView, so how can I do that?
My code:
DataTable table = new DataTable();
DataColumn col1 = new DataColumn("Name");
DataColumn col2 = new DataColumn("Username");
col1.DataType = System.Type.GetType("System.String");
col2.DataType = System.Type.GetType("System.String");
table.Columns.Add(col1);
table.Columns.Add(col2);
DataRow row = table.NewRow();
row[col1] = "John";
row[col2] = "John123";
table.Rows.Add(row);
GridView gv = new GridView();
gv.DataSource = table;
gv.DataBind();
推荐答案
检查此博客
http://msdn.microsoft.com/en-us/magazine/cc163709.aspx [ ^ ]
--NDK
check this blog
http://msdn.microsoft.com/en-us/magazine/cc163709.aspx[^]
--NDK
请尝试以下操作:
如何使用C#中的SQL语句填充DataGridView,GridView
Try following:
How to populate DataGridView, GridView with SQL statement in C#
这篇关于如何使用DataView创建一个DataTable并用数据库中的数据填充它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!