DataSource Class

System.Data.Generic

DataSource Class
Enables easy data access to SQL server.
Inheritance Hierarchy
SystemObject  System.Data.GenericDataSource

Namespace: System.Data.Generic
Assembly: System.Data.Generic (in System.Data.Generic.dll) Version: 1.9.5473.30542 (1.9.5473.2392)
Syntax
public sealed class DataSource : IDisposable
Public NotInheritable Class DataSource
	Implements IDisposable
public ref class DataSource sealed : IDisposable
[<SealedAttribute>]
type DataSource =  
    class
        interface IDisposable
    end

The DataSource type exposes the following members.

Constructors
  NameDescription
Public methodDataSource(String)
Returns a new instance of the DataSource class, and opens the connection immediately.
Public methodDataSource(String, Boolean)
Returns a new instance of the DataSource class.
Public methodDataSource(ConnectionStringBuilder, Boolean)
Returns a new instance of the DataSource class, using a connectionstring builder.
Top
Methods
  NameDescription
Public methodClearPool
Empties the connection pool associated with the current connection.
Public methodStatic memberClearPools
Empties all connection pool(s).
Public methodClose Obsolete.
Close the data connection.
Public methodCommitTransaction Obsolete.
Commits a transaction from the specified context.
Public methodCreateTransaction
Create a new transaction context.
Public methodCreateTransaction(String)
Create a new transaction context and leaves the connection open.
Public methodDispose
Releases all resources used by the Component.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodStatic memberEscapeSql(String)
Escapes standard SQL characters.
Public methodStatic memberEscapeSql(String, Object) Obsolete.
Escapes standard SQL characters. Can be used as String.Format.
Public methodExecuteCallBack
Executes the query, and raises a callback of ItemCallBackDelegate for each item it iterates.
Public methodExecuteDataSet
Executes the SQL query and returns a DataSet.
Public methodExecuteDataTable
Sends the SQL Query to the Connection and returns a DataTable.
Public methodExecuteDictionary
Executes the SQL statement and returns a dictionary of the first row. Keys in the dictionary are field names and values associated.
Public methodExecuteListT
Executes the query, and returns a collection of the first column.
Public methodExecuteNObjectsT
Executes the query, and returns a collection of object by the type T; hieratically compounded by the provided SQL JOIN and realted classes.
Public methodExecuteNoReturn(String)
Executes the Query against the datasource without returning any value.
Public methodExecuteNoReturn(String, TransactionContext)
Executes the Query against the datasource without returning any value. Supports transactions.
Public methodExecuteObjectT
Executes the query, and returns a object by the type T.
Public methodExecuteObjectsT
Executes the query, and returns a collection of object by the type T.
Public methodExecuteReader
Sends the SQL Query to the Connection and builds a SqlDataReader.
Public methodExecuteScalar(String)
Executes the query, and returns the first column of the first row in the result set returned by the query.
Public methodExecuteScalarT(String)
Executes the query, and returns the first column of the first row in the result set returned by the query.
Public methodExecuteScalarT(String, T)
Executes the query, and returns the first column of the first row in the result set returned by the query.
Public methodExecuteScalarT(String, TransactionContext, T)
Executes the query, and returns the first column of the first row in the result set returned by the query. Supports transactions.
Public methodExecuteXmlReader
Executes the Query against the datasource and returns a XML reader.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodOpen Obsolete.
Open the data connection.
Public methodStatic memberPrepareSql
Formats a SQL statement based on the data type of the parameters parameters.
Public methodRollbackTransaction Obsolete.
Rolls back a transaction from the specified context.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyConnectionState Obsolete.
Returns the connection state of the data connection.
Public propertyConnectionString
Returns the connection string of the current data connection.
Public propertyStatic memberCurrent
Returns a new instance of the DataSource class using the connection string, specific in the app.config.
Public propertyStatic memberSerializationSettings
Returns the settings for serialization.
Top
Remarks
Enables global data access by editing web.config, app.config or the Azure configuration file, and adding GlobalDataSource to the appSettings configuration elements.
Examples
<appSettings><add key="GlobalDataSource" value="Server=.\SQLExpress;Database=somedatabase;" /></appSettings>
Usage example 1 (get instance into variable):
DataSource source = DataSource.Current();
Usage example 2 (use static method):
DataSource.Current.ExecuteNoReturn("select * from table");
Usage example 3 (create an instance):
DataSource source = new DataSource("Server=.\SQLExpress;Database=somedatabase;");
source.ExecuteNoReturn("select * from table");
See Also