Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / SqlClient / SqlDataAdapter.cs / 1 / SqlDataAdapter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.SqlClient {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data.Common;
using System.Diagnostics;
[
DefaultEvent("RowUpdated"),
ToolboxItem("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, " + AssemblyRef.MicrosoftVSDesigner),
Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, " + AssemblyRef.MicrosoftVSDesigner)
]
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable {
static private readonly object EventRowUpdated = new object();
static private readonly object EventRowUpdating = new object();
private SqlCommand _deleteCommand, _insertCommand, _selectCommand, _updateCommand;
private SqlCommandSet _commandSet;
private int _updateBatchSize = 1;
public SqlDataAdapter() : base() {
GC.SuppressFinalize(this);
}
public SqlDataAdapter(SqlCommand selectCommand) : this() {
SelectCommand = selectCommand;
}
public SqlDataAdapter(string selectCommandText, string selectConnectionString) : this() {
SqlConnection connection = new SqlConnection(selectConnectionString);
SelectCommand = new SqlCommand(selectCommandText, connection);
}
public SqlDataAdapter(string selectCommandText, SqlConnection selectConnection) : this() {
SelectCommand = new SqlCommand(selectCommandText, selectConnection);
}
private SqlDataAdapter(SqlDataAdapter from) : base(from) { // Clone
GC.SuppressFinalize(this);
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_DeleteCommand),
]
new public SqlCommand DeleteCommand {
get { return _deleteCommand; }
set { _deleteCommand = value; }
}
IDbCommand IDbDataAdapter.DeleteCommand {
get { return _deleteCommand; }
set { _deleteCommand = (SqlCommand)value; }
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_InsertCommand),
]
new public SqlCommand InsertCommand {
get { return _insertCommand; }
set { _insertCommand = value; }
}
IDbCommand IDbDataAdapter.InsertCommand {
get { return _insertCommand; }
set { _insertCommand = (SqlCommand)value; }
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Fill),
ResDescriptionAttribute(Res.DbDataAdapter_SelectCommand),
]
new public SqlCommand SelectCommand {
get { return _selectCommand; }
set { _selectCommand = value; }
}
IDbCommand IDbDataAdapter.SelectCommand {
get { return _selectCommand; }
set { _selectCommand = (SqlCommand)value; }
}
override public int UpdateBatchSize {
get {
return _updateBatchSize;
}
set {
if (0 > value) { // WebData 98157
throw ADP.ArgumentOutOfRange("UpdateBatchSize");
}
_updateBatchSize = value;
Bid.Trace(" %d#, %d\n", ObjectID, value);
}
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_UpdateCommand),
]
new public SqlCommand UpdateCommand {
get { return _updateCommand; }
set { _updateCommand = value; }
}
IDbCommand IDbDataAdapter.UpdateCommand {
get { return _updateCommand; }
set { _updateCommand = (SqlCommand)value; }
}
[
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdated),
]
public event SqlRowUpdatedEventHandler RowUpdated {
add {
Events.AddHandler(EventRowUpdated, value);
}
remove {
Events.RemoveHandler(EventRowUpdated, value);
}
}
[
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdating),
]
public event SqlRowUpdatingEventHandler RowUpdating {
add {
SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
// MDAC 58177, 64513
// prevent someone from registering two different command builders on the adapter by
// silently removing the old one
if ((null != handler) && (value.Target is DbCommandBuilder)) {
SqlRowUpdatingEventHandler d = (SqlRowUpdatingEventHandler) ADP.FindBuilder(handler);
if (null != d) {
Events.RemoveHandler(EventRowUpdating, d);
}
}
Events.AddHandler(EventRowUpdating, value);
}
remove {
Events.RemoveHandler(EventRowUpdating, value);
}
}
override protected int AddToBatch(IDbCommand command) {
int commandIdentifier = _commandSet.CommandCount;
_commandSet.Append((SqlCommand)command);
return commandIdentifier;
}
override protected void ClearBatch() {
_commandSet.Clear();
}
object ICloneable.Clone() {
return new SqlDataAdapter(this);
}
override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
return new SqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
}
override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
return new SqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
}
override protected int ExecuteBatch() {
Debug.Assert(null != _commandSet && (0 < _commandSet.CommandCount), "no commands");
return _commandSet.ExecuteNonQuery();
}
override protected IDataParameter GetBatchedParameter(int commandIdentifier, int parameterIndex) {
Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range");
Debug.Assert(parameterIndex < _commandSet.GetParameterCount(commandIdentifier), "parameter out of range");
IDataParameter parameter = _commandSet.GetParameter(commandIdentifier, parameterIndex);
return parameter;
}
override protected bool GetBatchedRecordsAffected(int commandIdentifier, out int recordsAffected, out Exception error) {
Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range");
return _commandSet.GetBatchedAffected(commandIdentifier, out recordsAffected, out error);
}
override protected void InitializeBatching() {
Bid.Trace(" %d#\n", ObjectID);
_commandSet = new SqlCommandSet();
SqlCommand command = SelectCommand;
if (null == command) {
command = InsertCommand;
if (null == command) {
command = UpdateCommand;
if (null == command) {
command = DeleteCommand;
}
}
}
if (null != command) {
_commandSet.Connection = command.Connection;
_commandSet.Transaction = command.Transaction;
_commandSet.CommandTimeout = command.CommandTimeout;
}
}
override protected void OnRowUpdated(RowUpdatedEventArgs value) {
SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler) Events[EventRowUpdated];
if ((null != handler) && (value is SqlRowUpdatedEventArgs)) {
handler(this, (SqlRowUpdatedEventArgs) value);
}
base.OnRowUpdated(value);
}
override protected void OnRowUpdating(RowUpdatingEventArgs value) {
SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
if ((null != handler) && (value is SqlRowUpdatingEventArgs)) {
handler(this, (SqlRowUpdatingEventArgs) value);
}
base.OnRowUpdating(value);
}
override protected void TerminateBatching() {
if (null != _commandSet) {
_commandSet.Dispose();
_commandSet = null;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.SqlClient {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data.Common;
using System.Diagnostics;
[
DefaultEvent("RowUpdated"),
ToolboxItem("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, " + AssemblyRef.MicrosoftVSDesigner),
Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, " + AssemblyRef.MicrosoftVSDesigner)
]
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable {
static private readonly object EventRowUpdated = new object();
static private readonly object EventRowUpdating = new object();
private SqlCommand _deleteCommand, _insertCommand, _selectCommand, _updateCommand;
private SqlCommandSet _commandSet;
private int _updateBatchSize = 1;
public SqlDataAdapter() : base() {
GC.SuppressFinalize(this);
}
public SqlDataAdapter(SqlCommand selectCommand) : this() {
SelectCommand = selectCommand;
}
public SqlDataAdapter(string selectCommandText, string selectConnectionString) : this() {
SqlConnection connection = new SqlConnection(selectConnectionString);
SelectCommand = new SqlCommand(selectCommandText, connection);
}
public SqlDataAdapter(string selectCommandText, SqlConnection selectConnection) : this() {
SelectCommand = new SqlCommand(selectCommandText, selectConnection);
}
private SqlDataAdapter(SqlDataAdapter from) : base(from) { // Clone
GC.SuppressFinalize(this);
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_DeleteCommand),
]
new public SqlCommand DeleteCommand {
get { return _deleteCommand; }
set { _deleteCommand = value; }
}
IDbCommand IDbDataAdapter.DeleteCommand {
get { return _deleteCommand; }
set { _deleteCommand = (SqlCommand)value; }
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_InsertCommand),
]
new public SqlCommand InsertCommand {
get { return _insertCommand; }
set { _insertCommand = value; }
}
IDbCommand IDbDataAdapter.InsertCommand {
get { return _insertCommand; }
set { _insertCommand = (SqlCommand)value; }
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Fill),
ResDescriptionAttribute(Res.DbDataAdapter_SelectCommand),
]
new public SqlCommand SelectCommand {
get { return _selectCommand; }
set { _selectCommand = value; }
}
IDbCommand IDbDataAdapter.SelectCommand {
get { return _selectCommand; }
set { _selectCommand = (SqlCommand)value; }
}
override public int UpdateBatchSize {
get {
return _updateBatchSize;
}
set {
if (0 > value) { // WebData 98157
throw ADP.ArgumentOutOfRange("UpdateBatchSize");
}
_updateBatchSize = value;
Bid.Trace(" %d#, %d\n", ObjectID, value);
}
}
[
DefaultValue(null),
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_UpdateCommand),
]
new public SqlCommand UpdateCommand {
get { return _updateCommand; }
set { _updateCommand = value; }
}
IDbCommand IDbDataAdapter.UpdateCommand {
get { return _updateCommand; }
set { _updateCommand = (SqlCommand)value; }
}
[
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdated),
]
public event SqlRowUpdatedEventHandler RowUpdated {
add {
Events.AddHandler(EventRowUpdated, value);
}
remove {
Events.RemoveHandler(EventRowUpdated, value);
}
}
[
ResCategoryAttribute(Res.DataCategory_Update),
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdating),
]
public event SqlRowUpdatingEventHandler RowUpdating {
add {
SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
// MDAC 58177, 64513
// prevent someone from registering two different command builders on the adapter by
// silently removing the old one
if ((null != handler) && (value.Target is DbCommandBuilder)) {
SqlRowUpdatingEventHandler d = (SqlRowUpdatingEventHandler) ADP.FindBuilder(handler);
if (null != d) {
Events.RemoveHandler(EventRowUpdating, d);
}
}
Events.AddHandler(EventRowUpdating, value);
}
remove {
Events.RemoveHandler(EventRowUpdating, value);
}
}
override protected int AddToBatch(IDbCommand command) {
int commandIdentifier = _commandSet.CommandCount;
_commandSet.Append((SqlCommand)command);
return commandIdentifier;
}
override protected void ClearBatch() {
_commandSet.Clear();
}
object ICloneable.Clone() {
return new SqlDataAdapter(this);
}
override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
return new SqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
}
override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
return new SqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
}
override protected int ExecuteBatch() {
Debug.Assert(null != _commandSet && (0 < _commandSet.CommandCount), "no commands");
return _commandSet.ExecuteNonQuery();
}
override protected IDataParameter GetBatchedParameter(int commandIdentifier, int parameterIndex) {
Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range");
Debug.Assert(parameterIndex < _commandSet.GetParameterCount(commandIdentifier), "parameter out of range");
IDataParameter parameter = _commandSet.GetParameter(commandIdentifier, parameterIndex);
return parameter;
}
override protected bool GetBatchedRecordsAffected(int commandIdentifier, out int recordsAffected, out Exception error) {
Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range");
return _commandSet.GetBatchedAffected(commandIdentifier, out recordsAffected, out error);
}
override protected void InitializeBatching() {
Bid.Trace(" %d#\n", ObjectID);
_commandSet = new SqlCommandSet();
SqlCommand command = SelectCommand;
if (null == command) {
command = InsertCommand;
if (null == command) {
command = UpdateCommand;
if (null == command) {
command = DeleteCommand;
}
}
}
if (null != command) {
_commandSet.Connection = command.Connection;
_commandSet.Transaction = command.Transaction;
_commandSet.CommandTimeout = command.CommandTimeout;
}
}
override protected void OnRowUpdated(RowUpdatedEventArgs value) {
SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler) Events[EventRowUpdated];
if ((null != handler) && (value is SqlRowUpdatedEventArgs)) {
handler(this, (SqlRowUpdatedEventArgs) value);
}
base.OnRowUpdated(value);
}
override protected void OnRowUpdating(RowUpdatingEventArgs value) {
SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
if ((null != handler) && (value is SqlRowUpdatingEventArgs)) {
handler(this, (SqlRowUpdatingEventArgs) value);
}
base.OnRowUpdating(value);
}
override protected void TerminateBatching() {
if (null != _commandSet) {
_commandSet.Dispose();
_commandSet = null;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LexicalChunk.cs
- DataRecord.cs
- TypeForwardedToAttribute.cs
- QilInvokeEarlyBound.cs
- EnumMember.cs
- TypeElementCollection.cs
- DesignerCommandAdapter.cs
- InputLanguageCollection.cs
- QueryOptionExpression.cs
- SplashScreen.cs
- RelativeSource.cs
- Trace.cs
- GridViewItemAutomationPeer.cs
- SafeNativeMethods.cs
- shaperfactoryquerycacheentry.cs
- SemaphoreSecurity.cs
- TableLayoutSettingsTypeConverter.cs
- NamedPipeTransportBindingElement.cs
- RangeValueProviderWrapper.cs
- DrawingAttributeSerializer.cs
- GenericArgumentsUpdater.cs
- FontStretches.cs
- WorkflowOperationErrorHandler.cs
- TableRowGroupCollection.cs
- ServiceAuthorizationElement.cs
- CollectionViewGroupRoot.cs
- BindingExpression.cs
- PartialCachingAttribute.cs
- Range.cs
- AppSettingsExpressionBuilder.cs
- StoreUtilities.cs
- EdmSchemaAttribute.cs
- XsltLibrary.cs
- SqlConnectionManager.cs
- EventHandlersStore.cs
- DataBindingList.cs
- ParameterBinding.cs
- NetworkInterface.cs
- Model3DGroup.cs
- sapiproxy.cs
- XmlSerializationWriter.cs
- MetafileHeader.cs
- DefaultBinder.cs
- DataRecordObjectView.cs
- SafeNativeMethods.cs
- Font.cs
- DesignerVerb.cs
- ScriptingWebServicesSectionGroup.cs
- SuppressIldasmAttribute.cs
- TypeSystemHelpers.cs
- SqlCacheDependencySection.cs
- BidOverLoads.cs
- TileBrush.cs
- ConnectionProviderAttribute.cs
- DecimalStorage.cs
- RC2CryptoServiceProvider.cs
- RemotingClientProxy.cs
- DecoderFallbackWithFailureFlag.cs
- LinkedResourceCollection.cs
- XamlPointCollectionSerializer.cs
- FixedTextView.cs
- SqlDataSourceFilteringEventArgs.cs
- DataGridTablesFactory.cs
- CompositeKey.cs
- PropertyMappingExceptionEventArgs.cs
- NativeMethods.cs
- SafeFileMapViewHandle.cs
- SoapAttributes.cs
- EdgeProfileValidation.cs
- Partitioner.cs
- SqlRemoveConstantOrderBy.cs
- StringAttributeCollection.cs
- SimpleWebHandlerParser.cs
- StylusShape.cs
- MethodBody.cs
- SqlErrorCollection.cs
- MaterialGroup.cs
- securestring.cs
- AppDomainProtocolHandler.cs
- ListenerElementsCollection.cs
- CompiledRegexRunner.cs
- SendMailErrorEventArgs.cs
- ClientConvert.cs
- EmbossBitmapEffect.cs
- DataReaderContainer.cs
- ObjectStorage.cs
- DiagnosticTraceSchemas.cs
- WebPartManager.cs
- ThrowHelper.cs
- OracleConnectionStringBuilder.cs
- CodeComment.cs
- SupportingTokenSecurityTokenResolver.cs
- StringBlob.cs
- SAPICategories.cs
- PositiveTimeSpanValidatorAttribute.cs
- RegexTree.cs
- HttpHandler.cs
- MailWriter.cs
- ToolboxItemAttribute.cs
- WebPartDeleteVerb.cs