Skip to main content

ADO.NET Data Providers



ADO is the only way to work around a server cursor. ADO provides a schema management API to .Net 1.x. But ADO data (recordset) can’t be directly bound to ASP.NET controls.





Accessing SQL Server by using the managed provider for OLE DB adds overhead because the objects called must pass through the COM interop layer.









OLDB provider do not work with those implementing OLEDB 2.5 interfaces for semistructured and hierarchal rowset that includes Exchange (EXOLEDB) and Internet Publishing (MSDAIPP). 


Linq Data Source:

There are five types of linq datasources:
Linq-to-SQL, Linq-to-Objects, Linq-to-XML, and Linq-to-DataSet, and Linq-to-Entities.

LinqDataSource provide the following properties:

AutoGenerateOrderByClause (by using OrderByParameterCollection),
AutoGenerateWhereClause (By using WhereParameterCollection),
AutoPage, AutoSort, (They automatically enable Page sorting for GridView etc if enabled)
ContextTypeName (Class name), EnableDelete, EnableInsert, EnableUpdate, GroupBy, OrderBy, Select, StoreOriginalValuesInViewState,
TableName (Property/table name returning IEnumerable source), Where


public class Employee
{
    public string sName { get;set; }
    public string FName { get; set; }
    public string LName { get; set; }
}
public class SimpleList
{
    public static List<Employee> GetData {
        get{
            return new List<Employee> {
                new Employee { FName="Mubbasher", LName="Mukhtar", sName="MR"},
                new Employee { FName="Asad", LName="Mukhtar", sName="MR"}};
        }
    }
}

 <asp:LinqDataSource ID="LinqDataSource1" runat="server"
        ContextTypeName="SimpleList" TableName="GetData"
        Select="new ( sName,FName )" >
  </asp:LinqDataSource>

Providing Rich Selection Statement:

<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="NorthwindDataContext" TableName="Customers" OnSelecting="LinqDataSource1_Selecting" />


private NorthwindDataContext db;
protected void Page_Init(object sender, EventArgs e)
{
          db = new NorthwindDataContext();
          LinqDataSource1.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>( LinqDataSource1_Selecting);
}

protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
          var countries = (from c in db.Customers
                             select new { c.Country }).Distinct();
          e.Result = countries;
}

var data = from o in orders
           join c in customers
           on   o.Field<string>("CustomerID")
                equals c.Field<string>("CustomerID")
           where o.Field<DateTime>("OrderDate").Year == 1998 &&
                 o.Field<DateTime>("OrderDate").Month == 1 &&
                 o.Field<DateTime>("OrderDate").Day < 10
           select new {OrderID=o.Field<int>("OrderID"),
                       Company=c.Field<string>("CompanyName")};

Linq-To-Object works only for those implementing IEnumerable and IQueryable interfaces. Almost all built-in collections implement these interfaces.
 

Popular posts from this blog

Culture Information and Localization in .NET

Namespace: System.Globalization CultureInfo Class:                 It provides information like the Format of numbers and dates, Culture’s Calendar, Culture’s language and sublanguage (if applicable), Country and region of the culture. The Basic use of CultureInfo class is shown here: • How string Comparisons are performed • How Number Comparison & Formats are performed • Date Comparison and Formats. • How resources are retrieved and used. Cultures are grouped into three categories: Invariant Culture : It’s Culture Insensitive. It can be used to build some trial application. It can be also used to build an application with hard-coded expiry date that ignores cultures. But using it for every comparison will be incorrect and inappropriate. Neutral Culture : English(en), Frensh(fr), and Spanish(sp). A neutral culture is related to language but it’s not related to specific regi...

Data Serialization in .Net

Namespace: System.Runtime.Serialization Serialization is the process of converting object so that they can be transmitted over the network, or stored in file for later use, or passing them to a web service or any other application. .Net WebServices, Session Object, .Net Remoting and clipboard rely on Serialization. Binary Serialization: It’s efficient but not portable solution. String data = “Hello”; FileStream fs = new FileStream(“FileStream.Data”, FileMode.Create); BinaryFormatter bf = new BinarFormatter (); Bf.Serilize(fs, data); //Wrting Objects Bf.Serilize(fs,System.DateTime.Now); Fs.close(); Deserializing Objects FileStream fs = new FileStream(“FileStream.Data”, FileMode.Open); BinaryFormatter bf = new BinarFormatter (); String Data = (String)bf.Deserialize(fs); DateTime vTime = (DateTime) bf.Derialize(fs); To serialize a class one must the Serializeable attribute to that class. To omit some attribute from deseriali...

Using ADO.NET Transaction Object, Saving CLR Objects and SqlNotificationRequest

Serializable allows one transaction to complete before the other start. SqlConnectoin support named savpoint to roll back to; that’s an equaliant to save transaction command in MS SQL Server. Using TransactionScope Object : A transaction can’t span multiple connections.   Local and distributed transaction ares supported in 1.x you have to Enterpeise seveices library to regiser multiple connections and then call EnlistDistributedTransaction. Distributed Transaction Coordinator is required for Distributed transaction that’s available on windows 2000 & +. In 2.X and later use TransactionScope object. Serializable allows one transaction to complete before the other start. SqlConnectoin support named savpoint to roll back to; that’s an equaliant to save transaction command in MS SQL Server. Using TransactionScope Object : Dispoase of the transaction must be called to complete the transaction. Distributed Transaction : ...