将sqldatareader转变成datatable的vb.net代码
发表于:2007-06-30来源:作者:点击数:
标签:
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.D
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
原文转自:http://www.ltesting.net