首页 > 编程 > .NET > 正文

将sqldatareader转变成datatable的vb.net代码

2024-07-10 13:02:46
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!
public function gettable(byval _reader as system.data.sqlclient.sqldatareader) as system.data.datatable
            on error resume next
            dim _table as system.data.datatable = _reader.getschematable()
            dim _dt as system.data.datatable = new system.data.datatable()
            dim _dc as system.data.datacolumn
            dim _row as system.data.datarow
            dim _al as system.collections.arraylist = new system.collections.arraylist()
            dim i = 0
            for i = 0 to _table.rows.count() - 1
                _dc = new system.data.datacolumn()
                if (not _dt.columns.contains(_table.rows(i)("columnname").tostring())) then
                    _dc.columnname = _table.rows(i)("columnname").tostring()
                    _dc.unique = convert.toboolean(_table.rows(i)("isunique"))
                    _dc.allowdbnull = convert.toboolean(_table.rows(i)("allowdbnull"))
                    _dc.readonly = convert.toboolean(_table.rows(i)("isreadonly"))
                    _dc.readonly = convert.toboolean(_table.rows(i)("isreadonly"))
                    _dc.readonly = convert.toboolean(_table.rows(i)("isreadonly"))
                    _dc.readonly = convert.toboolean(_table.rows(i)("isreadonly"))
                    _al.add(_dc.columnname)
                    _dt.columns.add(_dc)
                end if
            next
            while _reader.read()
                _row = _dt.newrow()
                for i = 0 to _al.count
                    _row(cstr(_al(i))) = _reader(cstr(_al(i)))
                next
                _dt.rows.add(_row)
            end while
            return _dt
        end function
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表