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...

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 : ...

Text Encoding and Decoding using .Net

Namespace: System.Text To read a file, an application must write information about the encoding in which the file was written. So, the application that creates a file must write encoding information, otherwise viewer will see block and question marks in file. Unicode UTF-32 encoding : Represents a character as sequence of four bytes (32 bits). UTF32Encoding class can be used in that perspective. Unicode UTF-16 encoding : Represents a character in 16 bits. UnicodeEncoding class can be used to convert to and from UTF-16 encoding. Unicode UTF-8 encoding : Unicode UTF-8 uses 8-bit, 16-bit, 24-bit, and up to 48-bit encoding. Values 0 through 127 use 8-bit encoding and exactly match ASCII values, 128 through 2047 use 16-bit encoding, and values from 2048 and 65535 uses 24-bit encoding. UTF8Encoding class can be used to convert to and from UTF-8 encoding. ASCII encoding : ASCII encoding encodes Latin alphabets as single 7-Bit ASCII character. It is not well su...