تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
Source Code "OleDbConnection"
#2
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Permissions


Namespace System.Data.OleDb
<DefaultEvent("RowUpdated"), Designer("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ToolboxItem("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>
Public Class OleDbDataAdapter
Inherits DbDataAdapter
Implements IDbDataAdapter, IDataAdapter, ICloneable


Private Shared EventRowUpdated As Object = New Object()


Private Shared EventRowUpdating As Object = New Object()


Private _deleteCommand As OleDbCommand


Private _insertCommand As OleDbCommand


Private _selectCommand As OleDbCommand


Private _updateCommand As OleDbCommand


<ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_RowUpdated")>
Public Custom Event RowUpdated As OleDbRowUpdatedEventHandler
AddHandler
MyBase.Events.[AddHandler](OleDbDataAdapter.EventRowUpdated, value)
End AddHandler
RemoveHandler
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdated, value)
End RemoveHandler
End Event


<ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_RowUpdating")>
Public Custom Event RowUpdating As OleDbRowUpdatingEventHandler
AddHandler
Dim oleDbRowUpdatingEventHandler As OleDbRowUpdatingEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdating), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler IsNot Nothing AndAlso TypeOf value.Target Is DbCommandBuilder Then
Dim oleDbRowUpdatingEventHandler2 As OleDbRowUpdatingEventHandler = CType(ADP.FindBuilder(oleDbRowUpdatingEventHandler), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler2 IsNot Nothing Then
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdating, oleDbRowUpdatingEventHandler2)
End If
End If
MyBase.Events.[AddHandler](OleDbDataAdapter.EventRowUpdating, value)
End AddHandler
RemoveHandler
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdating, value)
End RemoveHandler
End Event


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_DeleteCommand")>
Public Property DeleteCommand() As OleDbCommand
Get
Return Me._deleteCommand
End Get
Set(value As OleDbCommand)
Me._deleteCommand = value
End Set
End Property


Property DeleteCommand() As IDbCommand
Get
Return Me._deleteCommand
End Get
Set(value As IDbCommand)
Me._deleteCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_InsertCommand")>
Public Property InsertCommand() As OleDbCommand
Get
Return Me._insertCommand
End Get
Set(value As OleDbCommand)
Me._insertCommand = value
End Set
End Property


Property InsertCommand() As IDbCommand
Get
Return Me._insertCommand
End Get
Set(value As IDbCommand)
Me._insertCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Fill"), ResDescription("DbDataAdapter_SelectCommand")>
Public Property SelectCommand() As OleDbCommand
Get
Return Me._selectCommand
End Get
Set(value As OleDbCommand)
Me._selectCommand = value
End Set
End Property


Property SelectCommand() As IDbCommand
Get
Return Me._selectCommand
End Get
Set(value As IDbCommand)
Me._selectCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_UpdateCommand")>
Public Property UpdateCommand() As OleDbCommand
Get
Return Me._updateCommand
End Get
Set(value As OleDbCommand)
Me._updateCommand = value
End Set
End Property


Property UpdateCommand() As IDbCommand
Get
Return Me._updateCommand
End Get
Set(value As IDbCommand)
Me._updateCommand = CType(value, OleDbCommand)
End Set
End Property


Public Sub New()
GC.SuppressFinalize(Me)
End Sub


Public Sub New(selectCommand As OleDbCommand)
Me.[New]()
Me.SelectCommand = selectCommand
End Sub


Public Sub New(selectCommandText As String, selectConnectionString As String)
Me.[New]()
Dim connection As OleDbConnection = New OleDbConnection(selectConnectionString)
Me.SelectCommand = New OleDbCommand(selectCommandText, connection)
End Sub


Public Sub New(selectCommandText As String, selectConnection As OleDbConnection)
Me.[New]()
Me.SelectCommand = New OleDbCommand(selectCommandText, selectConnection)
End Sub


Private Sub New(from As OleDbDataAdapter)
MyBase.[New](from)
GC.SuppressFinalize(Me)
End Sub


Function Clone() As Object Implements ICloneable.Clone
Return New OleDbDataAdapter(Me)
End Function


Protected Override Function CreateRowUpdatedEvent(dataRow As DataRow, command As IDbCommand, statementType As StatementType, tableMapping As DataTableMapping) As RowUpdatedEventArgs
Return New OleDbRowUpdatedEventArgs(dataRow, command, statementType, tableMapping)
End Function


Protected Override Function CreateRowUpdatingEvent(dataRow As DataRow, command As IDbCommand, statementType As StatementType, tableMapping As DataTableMapping) As RowUpdatingEventArgs
Return New OleDbRowUpdatingEventArgs(dataRow, command, statementType, tableMapping)
End Function


Friend Shared Sub FillDataTable(dataReader As OleDbDataReader, <Out()> ParamArray dataTables As DataTable())
Dim oleDbDataAdapter As OleDbDataAdapter = New OleDbDataAdapter()
oleDbDataAdapter.Fill(dataTables, dataReader, 0, 0)
End Sub


Public Function Fill(dataTable As DataTable, ADODBRecordSet As Object) As Integer
Dim permissionSet As PermissionSet = New PermissionSet(PermissionState.None)
permissionSet.AddPermission(OleDbConnection.ExecutePermission)
permissionSet.AddPermission(New SecurityPermission(SecurityPermissionFlag.UnmanagedCode))
permissionSet.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataTable, ADODBRecordSet" & vbLf, MyBase.ObjectID)
Dim result As Integer
Try
If dataTable Is Nothing Then
Throw ADP.ArgumentNull("dataTable")
End If
If ADODBRecordSet Is Nothing Then
Throw ADP.ArgumentNull("adodb")
End If
result = Me.FillFromADODB(dataTable, ADODBRecordSet, Nothing, False)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Public Function Fill(dataSet As DataSet, ADODBRecordSet As Object, srcTable As String) As Integer
Dim permissionSet As PermissionSet = New PermissionSet(PermissionState.None)
permissionSet.AddPermission(OleDbConnection.ExecutePermission)
permissionSet.AddPermission(New SecurityPermission(SecurityPermissionFlag.UnmanagedCode))
permissionSet.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataSet, ADODBRecordSet, srcTable='%ls'" & vbLf, MyBase.ObjectID, srcTable)
Dim result As Integer
Try
If dataSet Is Nothing Then
Throw ADP.ArgumentNull("dataSet")
End If
If ADODBRecordSet Is Nothing Then
Throw ADP.ArgumentNull("adodb")
End If
If ADP.IsEmpty(srcTable) Then
Throw ADP.FillRequiresSourceTableName("srcTable")
End If
result = Me.FillFromADODB(dataSet, ADODBRecordSet, srcTable, True)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Private Function FillFromADODB(data As Object, adodb As Object, srcTable As String, multipleResults As Boolean) As Integer
Dim flag As Boolean = multipleResults
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction" & vbLf)
Dim aDORecordsetConstruction As UnsafeNativeMethods.ADORecordsetConstruction = TryCast(adodb, UnsafeNativeMethods.ADORecordsetConstruction)
Dim aDORecordConstruction As UnsafeNativeMethods.ADORecordConstruction = Nothing
If aDORecordsetConstruction IsNot Nothing Then
If multipleResults Then
Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>" & vbLf)
If(CType(adodb, UnsafeNativeMethods.Recordset15)).get_ActiveConnection() Is Nothing Then
multipleResults = False
End If
End If
Else
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction" & vbLf)
aDORecordConstruction = (TryCast(adodb, UnsafeNativeMethods.ADORecordConstruction))
If aDORecordConstruction IsNot Nothing Then
multipleResults = False
End If
End If
Dim num As Integer = 0
If aDORecordsetConstruction IsNot Nothing Then
Dim num2 As Integer = 0
Dim array As Object() = New Object(1)
Dim oleDbHResult As OleDbHResult
While True
Dim srcTable2 As String = Nothing
If TypeOf data Is DataSet Then
srcTable2 = OleDbDataAdapter.GetSourceTableName(srcTable, num2)
End If
Dim flag2 As Boolean
num += Me.FillFromRecordset(data, aDORecordsetConstruction, srcTable2, flag2)
If Not multipleResults Then
GoTo IL_120
End If
array(0) = DBNull.Value
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>" & vbLf)
Dim obj As Object
Dim obj2 As Object
oleDbHResult = (CType(adodb, UnsafeNativeMethods.Recordset15)).NextRecordset(obj, obj2)
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
If OleDbHResult.S_OK > oleDbHResult Then
Exit While
End If
adodb = obj2
If adodb Is Nothing Then
GoTo IL_120
End If
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction" & vbLf)
aDORecordsetConstruction = CType(adodb, UnsafeNativeMethods.ADORecordsetConstruction)
If flag2 Then
num2 += 1
End If
If aDORecordsetConstruction Is Nothing Then
GoTo IL_120
End If
End While
If CType((-2146825037), OleDbHResult) <> oleDbHResult Then
Dim errorInfo As UnsafeNativeMethods.IErrorInfo = Nothing
UnsafeNativeMethods.GetErrorInfo(0, errorInfo)
Dim empty As String = String.Empty
If errorInfo IsNot Nothing Then
ODB.GetErrorDescription(errorInfo, oleDbHResult, empty)
End If
Throw New COMException(empty, CInt(oleDbHResult))
End If
IL_120:
If aDORecordsetConstruction IsNot Nothing AndAlso (flag OrElse adodb Is Nothing) Then
Me.FillClose(True, aDORecordsetConstruction)
End If
Else
If aDORecordConstruction Is Nothing Then
Throw ODB.Fill_NotADODB("adodb")
End If
num = Me.FillFromRecord(data, aDORecordConstruction, srcTable)
If flag Then
Me.FillClose(False, aDORecordConstruction)
End If
End If
Return num
End Function


Private Function FillFromRecordset(data As Object, recordset As UnsafeNativeMethods.ADORecordsetConstruction, srcTable As String, <Out()> ByRef incrementResultCount As Boolean) As Integer
incrementResultCount = False
Dim obj As Object = Nothing
Dim chapter As IntPtr
Try
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>" & vbLf)
obj = recordset.get_Rowset()
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>" & vbLf)
chapter = recordset.get_Chapter()
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Catch ex As Exception
If Not ADP.IsCatchableExceptionType(ex) Then
Throw
End If
Throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", ex)
End Try
If obj IsNot Nothing Then
Dim commandBehavior As CommandBehavior = If((MissingSchemaAction.AddWithKey <> MyBase.MissingSchemaAction), CommandBehavior.[Default], CommandBehavior.KeyInfo)
commandBehavior = commandBehavior Or CommandBehavior.SequentialAccess
Dim oleDbDataReader As OleDbDataReader = Nothing
Try
Dim chapterHandle As ChapterHandle = ChapterHandle.CreateChapterHandle(chapter)
oleDbDataReader = New OleDbDataReader(Nothing, Nothing, 0, commandBehavior)
oleDbDataReader.InitializeIRowset(obj, chapterHandle, ADP.RecordsUnaffected)
oleDbDataReader.BuildMetaInfo()
incrementResultCount = (0 < oleDbDataReader.FieldCount)
If incrementResultCount Then
Dim result As Integer
If TypeOf data Is DataTable Then
result = MyBase.Fill(CType(data, DataTable), oleDbDataReader)
Return result
End If
result = MyBase.Fill(CType(data, DataSet), srcTable, oleDbDataReader, 0, 0)
Return result
End If
Finally
If oleDbDataReader IsNot Nothing Then
oleDbDataReader.Close()
End If
End Try
Return0
End If
Return0
End Function


Private Function FillFromRecord(data As Object, record As UnsafeNativeMethods.ADORecordConstruction, srcTable As String) As Integer
Dim obj As Object = Nothing
Try
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>" & vbLf)
obj = record.get_Row()
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Catch ex As Exception
If Not ADP.IsCatchableExceptionType(ex) Then
Throw
End If
Throw ODB.Fill_EmptyRecord("adodb", ex)
End Try
If obj IsNot Nothing Then
Dim commandBehavior As CommandBehavior = If((MissingSchemaAction.AddWithKey <> MyBase.MissingSchemaAction), CommandBehavior.[Default], CommandBehavior.KeyInfo)
commandBehavior = commandBehavior Or (CommandBehavior.SingleRow Or CommandBehavior.SequentialAccess)
Dim oleDbDataReader As OleDbDataReader = Nothing
Try
oleDbDataReader = New OleDbDataReader(Nothing, Nothing, 0, commandBehavior)
oleDbDataReader.InitializeIRow(obj, ADP.RecordsUnaffected)
oleDbDataReader.BuildMetaInfo()
Dim result As Integer
If TypeOf data Is DataTable Then
result = MyBase.Fill(CType(data, DataTable), oleDbDataReader)
Return result
End If
result = MyBase.Fill(CType(data, DataSet), srcTable, oleDbDataReader, 0, 0)
Return result
Finally
If oleDbDataReader IsNot Nothing Then
oleDbDataReader.Close()
End If
End Try
Return0
End If
Return0
End Function


Private Sub FillClose(isrecordset As Boolean, value As Object)
Dim oleDbHResult As OleDbHResult
If isrecordset Then
Bid.Trace("<oledb.Recordset15.Close|API|ADODB>" & vbLf)
oleDbHResult = (CType(value, UnsafeNativeMethods.Recordset15)).Close()
Bid.Trace("<oledb.Recordset15.Close|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
Else
Bid.Trace("<oledb._ADORecord.Close|API|ADODB>" & vbLf)
oleDbHResult = (CType(value, UnsafeNativeMethods._ADORecord)).Close()
Bid.Trace("<oledb._ADORecord.Close|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
End If
If OleDbHResult.S_OK < oleDbHResult AndAlso CType((-2146824584), OleDbHResult) <> oleDbHResult Then
Dim errorInfo As UnsafeNativeMethods.IErrorInfo = Nothing
UnsafeNativeMethods.GetErrorInfo(0, errorInfo)
Dim empty As String = String.Empty
If errorInfo IsNot Nothing Then
ODB.GetErrorDescription(errorInfo, oleDbHResult, empty)
End If
Throw New COMException(empty, CInt(oleDbHResult))
End If
End Sub


Protected Override Sub OnRowUpdated(value As RowUpdatedEventArgs)
Dim oleDbRowUpdatedEventHandler As OleDbRowUpdatedEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdated), OleDbRowUpdatedEventHandler)
If oleDbRowUpdatedEventHandler IsNot Nothing AndAlso TypeOf value Is OleDbRowUpdatedEventArgs Then
oleDbRowUpdatedEventHandler(Me, CType(value, OleDbRowUpdatedEventArgs))
End If
MyBase.OnRowUpdated(value)
End Sub


Protected Override Sub OnRowUpdating(value As RowUpdatingEventArgs)
Dim oleDbRowUpdatingEventHandler As OleDbRowUpdatingEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdating), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler IsNot Nothing AndAlso TypeOf value Is OleDbRowUpdatingEventArgs Then
oleDbRowUpdatingEventHandler(Me, CType(value, OleDbRowUpdatingEventArgs))
End If
MyBase.OnRowUpdating(value)
End Sub


Private Shared Function GetSourceTableName(srcTable As String, index As Integer) As String
If index = 0 Then
Return srcTable
End If
Return srcTable + index.ToString(CultureInfo.InvariantCulture)
End Function
End Class
End Namespace
microsoft partner
Team administrator
MCPD,MCITP,OCP,MP,MCC
Xprema Systems
الرد }}}
تم الشكر بواسطة: ابراهيم ايبو , Amir_Alzubidy , Amir_Alzubidy , asemshahen5


الردود في هذا الموضوع
Source Code "OleDbConnection" - بواسطة smss - 25-05-13, 04:18 AM
RE: Source Code "OleDbConnection" - بواسطة viv - 13-06-19, 01:31 AM
Source Code "OleDbConnection" - بواسطة smss - 25-05-13, 04:22 AM
Source Code "OleDbConnection" - بواسطة smss - 26-05-13, 06:56 PM
Source Code "OleDbConnection" - بواسطة DreamsDotNet - 26-05-13, 10:07 PM
Source Code "OleDbConnection" - بواسطة dhetos - 19-06-13, 01:08 PM
Source Code "OleDbConnection" - بواسطة أبو يعقوب - 23-07-13, 06:11 AM
Source Code "OleDbConnection" - بواسطة محمود رغمان - 01-08-13, 07:17 PM
Source Code "OleDbConnection" - بواسطة مبرمج بلا حدود - 02-08-13, 04:51 AM

التنقل السريع :


يقوم بقرائة الموضوع: