Convert Datatable To Recordset

  • Uploaded by: Muneeb Khan
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Convert Datatable To Recordset as PDF for free.

More details

  • Words: 160
  • Pages: 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

Related Documents

Recordset
November 2019 5
Convert
May 2020 14
Convert
November 2019 38
Convert
August 2019 59
Convert
June 2020 16

More Documents from ""

Shortcut Keys
November 2019 49
Tcp-ip Basics
November 2019 54
Learn Excel
November 2019 51
Java Look And Feel
November 2019 29