惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 小牛哥

招聘.NET软件工程师 2人 招聘.NET软件工程师 2人 招聘.NET高级程序员[深圳] Windows 2003不能用 '..' 表示父目录解决方法 使用JS创建虚拟目录,并引导进入浏览 判断一个字符是否为汉字 Migration from J2EE to .NET 无法打开 Web 项目“DottextWeb”问题的解决 如何解决一个小问题:当前不会命中断点 Lucene.Net的问题我找到了,郁闷 插入表情图标的功能 事务死锁的问题如何解决? 创建虚拟目录和移除虚拟目录 - 小牛哥 - 博客园 Unclean shutdown of previous Apache run? - 小牛哥 VB.NET实现Singleton模式 启动一个进层阻止当前线程 Asc和Chr 获得一个随机数 将Html代码转换为Text
使用DataReader填充DataTable
小牛哥 · 2004-09-25 · via 博客园 - 小牛哥

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(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  小牛哥  阅读(5723)  评论(10)    收藏  举报