You are on page 1of 76

12/07/21 Anand.pissey@gmail.

com 1
Introduction to ADO.NET

 ADO.NET is an evolution of the ADO data


access model that directly answers user
requirements for developing scalable
applications.
 It was architected for the web with scalability,
statelessness, and XML in mind.
 ADO.NET has some of the same objects from
ADO (like Connection and Command), and
introduces new objects: DataSets, DataReaders
and DataSetCommands.

12/07/21 Anand.pissey@gmail.com 2
Features of ADO.NET
 One of the new concepts is the XML based
DataSet.
 This object provides a consistent programming
model around flat, relational and hierarchical data.
 It does this by having no knowledge of the source
of its data and by representing the data that it
holds as collections and data types.
 Irrespective of the source of the data in the
DataSet , it is manipulated through the same set of
standard APIs.

12/07/21 Anand.pissey@gmail.com 3
Features of ADO.NET

 While the DataSet has no knowledge of the source


of its data, the managed provider has detailed and
specific information.
 The role of the managed provider is to connect, fill,
and persist the DataSet to and from data stores.
 The ADO and SQL Server managed providers that
are part of the .Net Framework provide three basic
objects:
 Commands
 Connections
 DataSetCommands
12/07/21 Anand.pissey@gmail.com 4
Features of ADO.NET

 The important distinction between this evolved


stage of ADO.NET and previous data architectures
is - the DataSet
 We can use the DataSet as standalone entity
 DataSet is analogous to a disconnected Recordset
that knows nothing about where the data came
from, or where it is going
 Inside a DataSet, much like a database, there are
tables/columns, relationships, constraints, views
etc

12/07/21 Anand.pissey@gmail.com 5
Features of ADO.NET
 DataSetCommand is the object that connects to
the database to fill the DataSet.
 In ADO, data processing has been primarily
connection based.
 Now, in an effort to make multi-tiered apps more
efficient, data processing is turning to a message
based approach.
 DataSetCommand provides a bridge to retrieve
and save data between a DataSet and its source
data store.

12/07/21 Anand.pissey@gmail.com 6
Features of ADO.NET
 When dealing with connections to databases there
are two different options:
ADO (System.Data.ADO)
SQL (System.Data.SQL)
 SQL libraries are written to talk directly to MS-SQL
server.
 In contrast, the ADO libraries are used to talk to
any OLEDB provider.

12/07/21 Anand.pissey@gmail.com 7
ADO.NET – Object Model
System.Data.SQL
SQLConnection
Class

SQLCommand
Class
SQLParameter
Class SQLDataSetCommand
Class

DataSet Class DataSource


MSSQL Server
12/07/21 Anand.pissey@gmail.com 8
SQLConnection Class
 A SQLConnection object represents a unique
session with a data source within SQL Server.
 SQLConnection is used in conjunction with
SQLDataSetCommand and SQLCommand to
increase performance when connecting to a MS-
SQL Server database.
 For all third party SQL server products, as well as
other OLEDB-supported databases, it is probably
best that you use ADO Connection.

12/07/21 Anand.pissey@gmail.com 9
SQLConnection Constructor
 When an instance of SQLConnection is created,
the read/write properties are set to initial values.
 public SQLConnection()
Initializes a new instance of SQLConnection class with no
parameters.
 public SQLConnection(string)
Initializes a new instance of SQLConnection class when
given a string containing the connection text
 public SQLConnection(string, string, string)
Initializes a new instance of SQLConnection class when
given a server, a password and a user ID.
12/07/21 Anand.pissey@gmail.com 10
SQLConnection Constructor
 public SQLConnection(string, string, string, string);
Initializes a new instance of SQLConnection class when given
a server, a password, an user ID, and a database to connect
to.
Example:
public void CreateSqlConnection() {
SQLConnection myConnection = new
SQLConnection("mySQLServer","sa","","northwind");
myConnection.ConnectionTimeout = 30;
myConnection.Open();
myConnection.IsolationLevel =
IsolationLevel.ReadCommitted;
}
12/07/21 Anand.pissey@gmail.com 11
SQLConnection Properties

 ConnectionString
Gets or sets the string used to open a data store in
SQL Server.
The default value is an empty string.
Many of the connection string values have
corresponding properties.
If errors in syntax are found when parsing, an
exception is thrown. Other errors can only be found
when an attempt is made to Open the connection

12/07/21 Anand.pissey@gmail.com 12
SQLConnection Properties
 ConnectionString (Contd…)
The string can only be set when the state of the
connection is closed
No escape sequences are supported.
The type of the value is irrelevant. Names are not
case sensitive.
 Exception:
InvalidOperationException
Raised if the ConnectionSting value is changed
when the connection is open or broken
12/07/21 Anand.pissey@gmail.com 13
SQLConnection Properties
 ConnectionTimeout
Gets or sets the time(in seconds) to wait while
establishing a connection before terminating the
attempt and generating an error.
Default is 15 seconds
Read-only while the connection is open.
 Exceptions
 InvalidOperationException - Raised when the
connection is broken.
 ArgumentException - Raised when the property
is set to a value less than 0.
12/07/21 Anand.pissey@gmail.com 14
SQLConnection Properties
 Database
Gets or sets the name of the current database or
the database to be used once a connection is
open.
The default value is an empty string.
 Exceptions
 InvalidOperationException - Raised when the
connection is broken.

12/07/21 Anand.pissey@gmail.com 15
SQLConnection Properties
 DataSource
Gets or sets the name of the datasource to connect
to.
 IsolationLevel
Gets or sets the isolation level used for local
transactions.
The IsolationLevel remains in effect until explicitly
changed, it can be changed at any time.
The new value is used at execution time, not parse
time.
12/07/21 Anand.pissey@gmail.com 16
SQLConnection Properties
 IsolationLevel (contd..)
If changed during a transaction, the expected
behavior of the server is to apply the new locking
level to all statements remaining.
The IsolationLevel property can be set or retrieved
only when the connection is open.
Exception
 InvalidOperationException
Raised when the connection is broken or when
the property is set or retrieved when the
connection is in any state but an open state.
12/07/21 Anand.pissey@gmail.com 17
SQLConnection Properties
 IsolationLevel (contd..)
If the connection is closed, the IsolationLevel
property is set to ReadCommitted.
If IsolationLevel is set while the connection is
open, a round-trip to the server will occur and an
informational message will be sent.

12/07/21 Anand.pissey@gmail.com 18
SQLConnection Properties
 IsolationLevel (contd..)
One of the IsolationLevel values.
 Chaos
 ReadCommitted
 ReadUncommitted
 RepeatableRead
 Serializable
 Unspecified
The default is ReadCommitted.
12/07/21 Anand.pissey@gmail.com 19
SQLConnection Properties
 IsolationLevel (contd..)
 Chaos
The pending changes from more highly isolated
transactions cannot be overwritten.
 ReadCommitted
Shared locks are held while the data is being
read to avoid dirty reads, but the data can be
changed before the end of the transaction,
resulting in non-repeatable reads or phantom
data.
12/07/21 Anand.pissey@gmail.com 20
SQLConnection Properties
 IsolationLevel (contd..)
 ReadUncommitted
A dirty read is possible, meaning that no shared
locks are issued and no exclusive locks are
honored.
 RepeatableRead
Locks are placed on all data that is used in a
query, preventing other users from updating the
data. Prevents non-repeatable reads but
phantom rows are still possible.
12/07/21 Anand.pissey@gmail.com 21
SQLConnection Properties
 IsolationLevel (contd..)
 Serializable
A range lock is placed on the DataSet,
preventing other users from updating or
inserting rows into the dataset until the
transaction is complete.
 Unspecified
A different isolation level than the one specified
is being used, but the level cannot be
determined.
12/07/21 Anand.pissey@gmail.com 22
SQLConnection Properties
 Password
Gets or sets the password to use when connecting.
 ServerVersion
Gets a string containing the version of the
connected SQL Server.
 State
Gets the current state of the connection.
Can have one of the following values
(contd..)
12/07/21 Anand.pissey@gmail.com 23
SQLConnection Properties
DBObjectState values
 Broken
 Closed
 Connecting
 Executing
 Fetching
 InTransaction
 Open
SQLManaged provider renders only Open,Closed
and Broken
12/07/21 Anand.pissey@gmail.com 24
SQLConnection Properties
 TransactionLevel
Gets the transaction level.
 UserID
Gets or sets the user ID to use when connecting.

12/07/21 Anand.pissey@gmail.com 25
SQLConnection Methods
 Open
Opens a database connection with the current
property settings.
Exceptions:
 NullReferenceException
The DataSource property was not set or was
set incorrectly.
 InvalidOperationException
The connection is broken or if the connection is
already open.
12/07/21 Anand.pissey@gmail.com 26
SQLConnection Methods
 Open (contd..)
Exceptions:
 SQLException
The connection-level error that occurred while
opening the connection.
 Close
Closes the connection to the database.

12/07/21 Anand.pissey@gmail.com 27
SQLConnection Methods
 Close (contd..)
Exceptions:
 InvalidOperationException
The connection is already closed or if a
transaction is still processing.
 SQLException
The connection-level error that occurred while
closing the connection.

12/07/21 Anand.pissey@gmail.com 28
SQLConnection Methods
 Clone
Creates a new instance of the object initialized
with the current connection string.
Returns an Object that is a clone of this
SQLConnection.
The new instance will be in a closed state.
The new instance will not contain any references
to delegates listening to events on the existing
connection.

12/07/21 Anand.pissey@gmail.com 29
SQLConnection Methods
 Example
public void CreateSqlConnection() {
string myConnectString = "userid=sa;password=;
database=northwind;server=mySQLServer";
SQLConnection myConnection = new
SQLConnection(myConnectString);
MessageBox.Show("ServerVersion: " +
myConnection.ServerVersion + "\nState: " +
myConnection.State.ToString() +
"\nTransactionLevel: " +
myConnection.TransactionLevel.ToString());
SQLConnection myConnClone = (SQLConnection)
myConnection.Clone();
12/07/21 Anand.pissey@gmail.com 30
}
SQLConnection Methods
 BeginTransaction
Begins a database transaction.
public override int BeginTransaction();
Or
public int BeginTransaction(string);
 Exception
An error occurred while trying to execute the
transaction.

12/07/21 Anand.pissey@gmail.com 31
SQLConnection Methods
 CommitTransaction
Commits the database transaction.
 Exception
An error occurred while trying to execute the
transaction.
 When overriding CommitTransaction in a derived
class, be sure to call the base class's
CommitTransaction method.

12/07/21 Anand.pissey@gmail.com 32
SQLConnection Methods
 RollbackTransaction
Rolls back a database transaction from a pending
state.
public override void RollbackTransaction();
public void RollbackTransaction(string);
 The transaction can only be rolled back from a
pending state.
 When overriding RollbackTransaction in a derived
class, be sure to call the base class's
RollbackTransaction method.
12/07/21 Anand.pissey@gmail.com 33
SQLConnection Methods
 SaveTransaction
Saves a point within the transaction that can be
rolled back to.
 Parameters
 savePointName - The name of the save point
within the transaction.
The savePointName can be used in later calls
to RollbackTransaction.
 Exception - ArgumentException
A save point name must be specified.
12/07/21 Anand.pissey@gmail.com 34
SQLConnection Methods
Example
public void RunSqlTransaction(string myConnString)
{ SQLConnection myConnection = new

SQLConnection(myConnString);
myConnection.Open();
myConnection.BeginTransaction("SampleTransa
ction");
myConnection.SaveTransaction("SampleSavePoint3");
myConnection.RollbackTransaction("SampleSav
ePoint3");
myConnection.Close();
}
12/07/21 Anand.pissey@gmail.com 35
SQLCommand Class
 Represents a Transact-SQL query to execute at a
SQL Server data source.
 To execute commands that return rows, use the
Execute method.
 To execute commands that are invocations of
Transact-SQL programs use the
ExecuteNonQuery method
 If you are using the DateTime structure when
generating SQL command text, use the DateTime
Format method instead of the ToString method to
convert DateTime.
12/07/21 Anand.pissey@gmail.com 36
SQLCommand Class
CONSTRUCTORS
 public SQLCommand();
Initializes a new instance of the SQLCommand class
without any parameters.

 public SQLCommand(string);
Initializes a new instance of the SQLCommand class with
the given command text.

 public SQLCommand(string, SQLConnection);


Initializes a new instance of the SQLCommand class with
the given command text and a SQLConnection.
12/07/21 Anand.pissey@gmail.com 37
SQLCommand Class
CONSTRUCTORS (Contd..)
 public SQLCommand(string, string);
Initializes a new instance of the SQLCommand class with the
given command text and a connection string.

 public SQLCommand(SQLConnection, string,


CommandType, SQLParameter[ ],
UpdateRowSource);
Initializes a new instance of the SQLCommand class with a
SQLConnection, the command text, a CommandType,
parameters, and an UpdateRowSource object used by the
SQLDataSetCommand to determine how the command
results
12/07/21
are to be applied to the row updated.
Anand.pissey@gmail.com 38
SQLCommand Properties
 Properties
 ActiveConnection
 CommandBehavior
 CommandText
 CommandTimeout
 CommandType
 Parameters
 RecordsAffected
 UpdatedRowSource

12/07/21 Anand.pissey@gmail.com 39
SQLCommand Properties
 Active Connection
Gets or sets the SQLConnection used by this
instance of the SQLCommand.
Returns the connection to a data source. The
default value is a null reference (in Visual Basic
Nothing).
When cloning a SQLCommand object, this property
is not cloned. Instead the reference to the
SQLConnection object is copied

12/07/21 Anand.pissey@gmail.com 40
SQLCommand Properties
 CommandBehavior
Gets or sets the behavior the SQLCommand is to
exhibit when executed.
Property Values
 KeyInfo
The query command is used to obtain key
information and schema information. The query
command will be executed without any locking
on the selected rows.

12/07/21 Anand.pissey@gmail.com 41
SQLCommand Properties
 CommandBehavior (contd..)
Property Values
 SchemaOnly
The query command returns column
information only, and not affect the database
state.
 SingleResult
The query command returns a single result,
and the execution of the query command can
affect the database state.
12/07/21 Anand.pissey@gmail.com 42
SQLCommand Properties
 CommandText

  Gets or sets the SQL text command to run against


the data source.
Property Value
 The SQL text command to execute.
When the CommandType property is set to
StoredProcedure, the CommandText property
should be set to the name of the stored procedure.

12/07/21 Anand.pissey@gmail.com 43
SQLCommand Properties
 CommandTimeout
Gets or sets the wait time before terminating the
 
attempt to execute and generating an error.
Property Value
 The time (in seconds) to wait for the command
to execute. The default value is 30 seconds.
Exception
 ArgumentException
Raised when the property is assigned a value less
than 0.
12/07/21 Anand.pissey@gmail.com 44
SQLCommand Properties
 CommandType

  Gets or sets how the CommandText property is to


be interpreted.
Property Value
One of the CommandType values. The default is
Text.
 StoredProcedure
 TableDirect
 Text
12/07/21 Anand.pissey@gmail.com 45
SQLCommand Properties
Exception
 NotSupportedException
 
The CommandType value of TableDirect is not
supported by SQLCommand.
Example:
public void CreateMySqlCommand() {
SQLCommand myCommand = new SQLCommand();
myCommand.CommandTimeout = 15;
myCommand.CommandType = CommandType.Text;
myCommand.CommandBehavior =
DBCommandBehavior.SingleResult;
Anand.pissey@gmail.com
}12/07/21 46
SQLCommand Properties
 Parameters
Gets the collection of SQLParameters.
Property Value
 The SQL parameters for the command.
Example:
public void CreateMySQLCommand(SQLConnection
myConnection, string mySelectQuery,
SQLParameter[] myParamArray) {

12/07/21 Anand.pissey@gmail.com 47
SQLCommand Properties
 Parameters
Example: (contd..)
SQLCommand myCommand = new SQLCommand
(myConnection,mySelectQuery, CommandType.Text,
myParamArray, UpdateRowSource.Both);
string myMessage = "";
for (int i = 0; i < myCommand.Parameters.Count; i++) {
myMessage +=myCommand.Parameters[i].ToString()
+"\n";
}
MessageBox.Show(myMessage);
}
12/07/21 Anand.pissey@gmail.com 48
SQLCommand Properties
 RecordsAffected
Returns the number of records affected by
execution of the command.
For most SQL statements, the value returned is 1 if
the command succeeds, and less than 1 if the
command fails.
Property Value
 The number of records affected.

12/07/21 Anand.pissey@gmail.com 49
SQLCommand Properties
 UpdatedRowSource
Gets or sets how command results are applied to
the DataSet when used by the Update method of a
DBDataSetCommand.
Properties
 Both
Both the output parameters and the first returned
record are mapped to the changed row in the
DataSet.

12/07/21 Anand.pissey@gmail.com 50
SQLCommand Properties
 UpdatedRowSource (contd..)
Properties
 FirstReturnedRecord
The data in the first returned record is mapped to
the changed row in the DataSet.
 None
Any returned parameters are ignored.

12/07/21 Anand.pissey@gmail.com 51
SQLCommand Properties
 UpdatedRowSource (contd..)
Properties
 OutputParameters
Output parameters are mapped to the changed row
in the DataSet.
Exceptions
 ArgumentException
The value entered was not one of the
UpdateRowSource values. 
12/07/21 Anand.pissey@gmail.com 52
SQLCommand Methods

 Execute
 ExecuteNonQuery
 Clone
 ResetParameters  

12/07/21 Anand.pissey@gmail.com 53
SQLCommand Methods
 Execute
Specifically used for Commands that return rows
from a data source
public void Execute(Object)
Executes the CommandText against the
ActiveConnection and returns a result Object
public new void Execute(SQLDataReader);
Executes the CommandText against the
ActiveConnection and builds a SQLDataReader.

12/07/21 Anand.pissey@gmail.com 54
SQLCommand Methods
 ExecuteNonQuery
Executes a SQL command that does not return any
rows against the ActiveConnection.
Return Value: The number of rows affected.
For update, insert, and delete statements, the
return value is the number of rows affected by the
command.
For all other types of statements, the return value
is -1.

12/07/21 Anand.pissey@gmail.com 55
SQLCommand Methods
 Example
public void CreateMySQLCommand(string
mySelectQuery,string myConnection) {
SQLCommand myCommand = new
SQLCommand(mySelectQuery,myConnection);
SQLCommand myCommCopy =
(SQLCommand) myCommand.Clone();
myCommand.ActiveConnection.Open();
myCommand.ExecuteNonQuery();
}

12/07/21 Anand.pissey@gmail.com 56
SQLCommand Methods
 Clone
Creates a cloned instance of this instance. Returns
an Object that is a clone of this instance.
The ActiveConnection is not cloned, but instead
shared.

Example (contd..)

12/07/21 Anand.pissey@gmail.com 57
SQLCommand Methods
 Clone Example (contd..)
public void CreateMySQLCommand(string
mySelectQuery,string myConnection) {
SQLCommand myCommand = new
SQLCommand(mySelectQuery,myConnection);
SQLCommand myCommCopy = (SQLCommand)
myCommand.Clone();
myCommand.ActiveConnection.Open();
SQLDataReader myDataReader;
myCommand.Execute(out myDataReader);
while(myDataReader.Read()) {
Console.WriteLine(myDataReader.GetString(0));
} }
12/07/21 Anand.pissey@gmail.com 58
SQLCommand Methods
 ResetParameters
 
Resets the parameters within the parameters
collection.
public void RefreshMyParameters(ADOCommand
myCommand) {
 
try { myCommand.ActiveConnection.Open(); }
catch (InvalidOperationException myOpenAttempt) { }
myCommand.ResetParameters();
string myMessage = "";
for (int i = 0; i < myCommand.Parameters.Count; i++) {
myMessage+= myCommand.Parameters[i].ToString()
+ "\n"; }
MessageBox.Show(myMessage); }
12/07/21 Anand.pissey@gmail.com 59
SQLParameter Class  
Constructors:
 
 public SQLParameter();
Initializes a new instance of the SQLParameter
class. This is the default constructor
 
 public SQLParameter(string, SQLDataType);
Initializes a new instance of the SQLParameter
class with the column name and the SQLDataType
of the column.

12/07/21 Anand.pissey@gmail.com 60
SQLParameter Class  
Constructors: (contd..)
 
 public SQLParameter(string, SQLDataType,int)
Initializes a new instance of the SQLParameter
class with the column name, the SQLDataType of
  the column, and the column size.
 public SQLParameter(string, SQLDataType, int,
string);
Initializes a new instance of the SQLParameter
class with the column name, the SQLDataType of
the column, the column size and the source
column name.
12/07/21 Anand.pissey@gmail.com 61
SQLParameter Class  
Constructors: (contd..)
 
 public SQLParameter(string, SQLDataType, int,
ParameterDirection, bool, byte, byte, string,
DataRowVersion, Object);
 
Initializes a new instance of the SQLParameter
class with the column name, the type of the field,
the size of the field, a ParameterDirection, the
precision of the parameter, the scale of the
parameter, the source column, a DataRowVersion
to use, the value of the parameter.

12/07/21 Anand.pissey@gmail.com 62
SQLParameter Properties 
 DatabaseType
   
Gets or sets the native data type from the data
source.
Property Value
 
One of the SQLDataType Enum values. The
default is Variant.
BigInt,Binary,Bit,Char,DateTime,Decimal,Float,Image,
Int,Money,Nchar,Ntext, NvarChar,Real, SmallDateTime,
SmallInt, SmallMoney,Text,Timestamp,TinyInt,UniqueId,
VarBinary,VarChar,Variant

12/07/21 Anand.pissey@gmail.com 63
SQLParameter Properties 
 DatabaseType (contd..)
   
Example:
public void CreateSqlParameter() {
  SQLParameter myParameter = new
SQLParameter();
myParameter.ParameterName = "Description";
myParameter.IsNullable = true;
myParameter.DatabaseType =
SQLDataType.VarChar; }

12/07/21 Anand.pissey@gmail.com 64
SQLParameter Properties  
 Direction
   
Gets or sets whether the parameter is input only,
output only, bidirectional, or a return value
parameter.
  Property Value
One of the ParameterDirection values. The default is
Input.
• Input
• InputOutput
• Output
• ReturnValue
12/07/21 Anand.pissey@gmail.com 65
SQLParameter Properties  
 Direction (contd..)
   
Example:
public void CreateSqlParameter() {

 
SQLParameter myParameter = new
SQLParameter();
myParameter.ParameterName = "Description";
myParameter.DatabaseType =
SQLDataType.VarChar;
myParameter.Direction =
ParameterDirection.Output;
}
12/07/21 Anand.pissey@gmail.com 66
SQLParameter Properties  
 IsNullable
   
Gets or sets whether the parameter accepts null
values.
Property Value
 
True if null values are accepted; otherwise, false.
The default is false.
 ParameterName Property 
Gets or sets the name of the SQLParameter.

12/07/21 Anand.pissey@gmail.com 67
SQLParameter Properties  
 Parent
   
Gets the reference to the SQLParameters collection
that is the parent of this instance.
Property Value
 
The reference to the SQLParameters collection that
is the parent of this instance.
 Value
Gets or sets the value of the parameter.

12/07/21 Anand.pissey@gmail.com 68
SQLParameter Properties  
 Precision
   
Gets or sets the maximum number of digits used to
represent the Value.
The maximum number of digits used to represent
the Value. The default value is 0.
 
Used by parameters which have a SQLDataType of
Decimal.
 Scale
Gets or sets the number of decimal places to which
Value is resolved.
The number of decimal places to which Value is
resolved. The default is 0.
12/07/21 Anand.pissey@gmail.com 69
SQLParameter Properties  
Example:
   
public void CreateSqlParameter() {
SQLParameter myParameter = new
SQLParameter();
 
myParameter.ParameterName = "Description";
myParameter.DatabaseType =
SQLDataType.Decimal;
myParameter.Value = 3.1416;
myParameter.Precision = 8;
myParameter.Scale = 4;
}
12/07/21 Anand.pissey@gmail.com 70
SQLParameter Properties  
 Size
 
Gets or sets the maximum size, in bytes, of the
data within the field.
This property is used for binary and string types.
For variable length data types, the Size property
describes the maximum amount of data to
transmit to the server.
For nonstring data types and ANSI string data,
Size refers to the number of bytes
If not explicitly set, the size is inferred from the
actual size of the specified parameter value.
12/07/21 Anand.pissey@gmail.com 71
SQLParameter Properties  
 SourceColumn
 
Gets or sets the name of the source column
mapped to the DataSet and used for loading or
returning the Value.
public void CreateSqlParameter() {
SQLParameter myParameter = new SQLParameter();
myParameter.ParameterName = "Description";
myParameter.IsNullable = true;
myParameter.DatabaseType = SQLDataType.VarChar;
myParameter.Direction = ParameterDirection.Output;
myParameter.SourceColumn = "Description";
}
12/07/21 Anand.pissey@gmail.com 72
SQLParameter Properties  
 SourceVersion
 
Gets or sets the DataRowVersion to use when
loading Value.
 Current
The row contains current values.
 Default
The row contains its default values.
 Original
The row contains its original values.
 Proposed
The row contains a proposed value.
12/07/21 Anand.pissey@gmail.com 73
SQLParameter Properties  
 SourceVersion(contd..)
 
This property is used by the Update Command
during the Update to determine whether the
original or current value is used for a parameter
value.
 This allows primary keys to be updated.
 This property is ignored by the Insert Command
and Delete Command.

12/07/21 Anand.pissey@gmail.com 74
SQLParameter Methods  
 Clone
   
Creates a copy of this SQLParameter object.
A new SQLParameter object that is a copy of this
instance.
 
When overriding Clone in a derived class, be sure
to call the base class's Clone method.

12/07/21 Anand.pissey@gmail.com 75
SQLParameter Methods  
Example:
   
public void CloneSqlParam() {
// ... // create myOrigParam // ... //
  SQLParameter myClone = (SQLParameter)
myOrigParam.Clone();
MessageBox.Show("me: " + myClone.ToString()
+ "\n" + "myParent: "
+
myClone.Parent.ToString()); }

12/07/21 Anand.pissey@gmail.com 76

You might also like