小牛哥
随笔 - 44, 文章 - 0, 评论 - 224, 引用 - 1
数据加载中……
使用DataReader填充DataTable
VB.NET
'
'' -----------------------------------------------------------------------------
'
'' <summary>
'
'' Fill DataTable from DataReader
'
'' </summary>
'
'' <param name="oDataReader">DataReader对象</param>
'
'' <returns>返回DataTable</returns>
'
'' <remarks>
'
'' </remarks>
'
'' <history>
'
'' [Administrator] 2004-9-25 小牛哥 创建
'
'' </history>
'
'' -----------------------------------------------------------------------------
Public
Function Fill()
Function
Fill(
ByRef
oDataReader
As
IDataReader)
As
DataTable
Dim
iLoop
As
Integer
Dim
oDataTable
As
DataTable
Dim
oSchemaTable
As
DataTable
Dim
oDataRow
As
DataRow
oDataTable
=
New
DataTable
oSchemaTable
=
New
DataTable
oSchemaTable
=
oDataReader.GetSchemaTable()
For
iLoop
=
0
To
oSchemaTable.Rows.Count
-
1
oDataTable.Columns.Add(oSchemaTable.Rows(iLoop)(
"
ColumnName
"
), oSchemaTable.Rows(iLoop)(
"
DataType
"
))
Next
While
oDataReader.Read
oDataRow
=
oDataTable.NewRow
For
iLoop
=
0
To
oSchemaTable.Rows.Count
-
1
oDataRow(iLoop)
=
oDataReader(oSchemaTable.Rows(iLoop)(
"
ColumnName
"
))
Next
oDataTable.Rows.Add(oDataRow)
End
While
oDataReader.Close()
oSchemaTable.Rows.Clear()
Return
oDataTable
End Function
C#
public
DataTable Fill(
ref
IDataReader oDataReader)
{
int
iLoop;
DataTable oDataTable;
DataTable oSchemaTable;
DataRow oDataRow;
oDataTable
=
new
DataTable();
oSchemaTable
=
new
DataTable();
oSchemaTable
=
oDataReader.GetSchemaTable();
for
(
int
iLoop
=
0
; iLoop
<=
oSchemaTable.Rows.Count
-
1
; iLoop
++
)
{
oDataTable.Columns.Add(oSchemaTable.Rows(iLoop)(
"
ColumnName
"
), oSchemaTable.Rows(iLoop)(
"
DataType
"
));
}
while
(oDataReader.Read)
{
oDataRow
=
oDataTable.NewRow;
for
(
int
iLoop
=
0
; iLoop
<=
oSchemaTable.Rows.Count
-
1
; iLoop
++
)
{
oDataRow(iLoop)
=
oDataReader(oSchemaTable.Rows(iLoop)(
"
ColumnName
"
));
}
oDataTable.Rows.Add(oDataRow);
}
oDataReader.Close();
oSchemaTable.Rows.Clear();
return
oDataTable;
}
posted on 2004-09-25 16:55
小牛哥
阅读(3177)
评论(10)
编辑
收藏
Powered by:
博客园
Copyright © 小牛哥
导航
博客园
首页
新随笔
联系
订阅
管理
<
2004年9月
>
日
一
二
三
四
五
六
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(39)
给我留言
查看留言
随笔档案
2005年11月 (1)
2005年8月 (2)
2005年4月 (2)
2004年12月 (1)
2004年11月 (6)
2004年10月 (2)
2004年9月 (14)
2004年7月 (1)
2004年6月 (15)
MyCategory
kaneboy
Meng Zhang
无忧脚本
小牛哥的首页
阅读排行榜
1. 西南师范大学网络教育学院2002秋毕业论文选题表(26901)
2. 如何让windows2003升级(17318)
3. Windows 2003不能用 '..' 表示父目录解决方法(9137)
4. 无法打开 Web 项目“DottextWeb”问题的解决(7015)
5. 尝试从 Web 项目中访问网络文件时服务器返回的常见错误的列表(3547)
评论排行榜
1. 如何让windows2003升级(73)
2. 西南师范大学网络教育学院2002秋毕业论文选题表(15)
3. Windows 2003不能用 '..' 表示父目录解决方法(13)
4. 无法打开 Web 项目“DottextWeb”问题的解决(11)
5. 使用DataReader填充DataTable(10)