Use of ASP.net dbproviderfactory-example _ practical Tips

Source: Internet
Author: User
Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

Using CrystalDecisions.CrystalReports.Engine;
Using Crystaldecisions.shared;
Using System.Data.Common;

<summary>
Summary description of Orderinfoconfiguration
</summary>
public class Orderinfoconfiguration
{
Private Const string connectionstring=@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\program files\ Tutorialsamplecodeprojects\xtreme.mdb ";
Private Const string querystring= "SELECT a.[order Date" As Order time, A.[order ID] As order number, B.[last name]+\ "\" +b.[first Name] As Employee name, C.[customer name] as customer name, d.[product name] as product name from Orders a,employee B,customer c,product D, [Orders Detail] e WH ERE a.[employee id]=b.[employee id] and A.[customer id]=c.[customer ID] and a.[order id]=e.[order ID] and e.[product ID]=d . [Product ID];

public static DataSet Orderinfodataset
{
Get
{
DataSet DataSet = new DataSet ();

DbProviderFactory factory = dbproviderfactories.getfactory ("System.Data.OleDb"); Get Factory
DbConnection con = factory. CreateConnection ();//Create Connection
Con. ConnectionString = ConnectionString;
DbCommand cmd = factory. CreateCommand ();//create command
Cmd.commandtext = querystring;
Cmd.commandtype = CommandType.Text;
Cmd. Connection = con;
DbDataAdapter Dapter = Factory. Createdataadapter ();//Create Adapter
Dapter. SelectCommand = cmd;
Dapter. Fill (dataSet);/

return dataSet;
}
}

Public Orderinfoconfiguration ()
{
//
TODO: Add constructor logic here
//
}
}

DbProviderFactory factory = dbproviderfactories.getfactory ("System.Data.OleDb"); Get a factory and you can use the factory to produce a variety of objects for the data provider.

If the connection

Sqlserver:dbproviderfactory factory = dbproviderfactories.getfactory ("System.Data.SqlClient");
Oracle:dbproviderfactory factory = dbproviderfactories.getfactory ("System.Data.OracleClient");
Odbc:dbproviderfactory factory = dbproviderfactories.getfactory ("System.Data.Odbc");

Use this, if want to change a database, is it very convenient? Oh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.