Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
6K views

Convert DataTable To RecordSet

This function converts a DataTable object to an ADODB Recordset object. It iterates through the columns of the DataTable, appending the column names and data types to the Recordset. It then iterates through the rows of the DataTable, adding the row data to the Recordset. Finally, it returns the populated Recordset. A secondary function translates .NET data types to ADODB data types.

Uploaded by

Muneeb Khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
6K views

Convert DataTable To RecordSet

This function converts a DataTable object to an ADODB Recordset object. It iterates through the columns of the DataTable, appending the column names and data types to the Recordset. It then iterates through the rows of the DataTable, adding the row data to the Recordset. Finally, it returns the populated Recordset. A secondary function translates .NET data types to ADODB data types.

Uploaded by

Muneeb Khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Public Function convertToADODB(ByRef table As DataTable) As ADODB.

Recordset
'Try
Dim result As New ADODB.Recordset

result.CursorLocation = CursorLocationEnum.adUseClient

Dim resultFields As ADODB.Fields = result.Fields

Dim col As DataColumn

For Each col In table.Columns


resultFields.Append(col.ColumnName, TranslateType(col.DataType),
col.MaxLength, col.AllowDBNull = ADODB.FieldAttributeEnum.adFldIsNullable)

Next

result.Open(System.Reflection.Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0)

For Each row As DataRow In table.Rows

result.AddNew(System.Reflection.Missing.Value,
System.Reflection.Missing.Value)

For i As Integer = 0 To table.Columns.Count


resultFields(i).Value = row(i)
Next
Next
Return result
'Catch ex As Exception

'End Try

End Function

Public Function TranslateType(ByRef type As Type) As ADODB.DataTypeEnum


Try
Select Case type.UnderlyingSystemType.ToString

Case "System.Boolean"
Return ADODB.DataTypeEnum.adBoolean

Case "System.Byte"
Return ADODB.DataTypeEnum.adUnsignedTinyInt

Case "System.Char"
Return ADODB.DataTypeEnum.adChar

Case "System.DateTime"
Return ADODB.DataTypeEnum.adDate

Case "System.Decimal"
Return ADODB.DataTypeEnum.adCurrency

Case "System.Double"
Return ADODB.DataTypeEnum.adDouble

Case "System.Int16"
Return ADODB.DataTypeEnum.adSmallInt

Case "System.Int32"
Return ADODB.DataTypeEnum.adInteger

Case "System.Int64"
Return ADODB.DataTypeEnum.adBigInt

Case "System.SByte"
Return ADODB.DataTypeEnum.adTinyInt

Case "System.Single"
Return ADODB.DataTypeEnum.adSingle

Case "System.UInt16"
Return ADODB.DataTypeEnum.adUnsignedSmallInt

Case "System.UInt32"
Return ADODB.DataTypeEnum.adUnsignedInt

Case "System.UInt64"
Return ADODB.DataTypeEnum.adUnsignedBigInt

Case "System.String"
'case default
Return ADODB.DataTypeEnum.adVarWChar

End Select

Catch ex As Exception
MsgBox(ex.Message)
End Try

End Function

You might also like