CopyCode The Code is 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>
/// Abstract 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. [order date] as order time,. [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 where. [employee ID] = B. [employee ID] and. [Customer ID] = C. [Customer ID] and. [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 the factory
Dbconnection con = factory. createconnection (); // create a connection
Con. connectionstring = connectionstring;
Dbcommand cmd = factory. createcommand (); // create a command
Cmd. commandtext = querystring;
Cmd. commandtype = commandtype. text;
Cmd. Connection = con;
Dbdataadapter dapter = factory. createdataadapter (); // create an adapter
Dapter. selectcommand = cmd;
Dapter. Fill (Dataset); // fill
Return dataset;
}
}
Public orderinfoconfiguration ()
{
//
// Todo: add the constructor logic here
//
}
}
Dbproviderfactory factory = dbproviderfactories. getfactory ("system. Data. oledb"); // you can obtain a factory by obtaining the factory statement. You can use this factory to produce and provide the data.Program.
For 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 ");
I used this. If I want to change the database, is it very convenient? Haha.