Adapt. NET data to [old code]

Source: Internet
Author: User
Add reference: system. configuration. dll, system. Windows. Forms. dll

Using system;
Using system. Collections. Generic;
Using system. text;

Using system. configuration;
Using system. Data;
Using system. Data. oledb;
Using system. Windows. forms;

Namespace patternsstudy3
{
Class Program
{
Static void main (string [] ARGs)
{
Application. Run (new show ());
}
}

/// <Summary>
/// Data class
/// </Summary>
Public class dataservice
{
/// <Summary>
/// Create a database connection
/// </Summary>
/// <Returns> database connection instance </returns>
/// <Remarks> Read the database connection string from the config file </remarks>
Public static oledbconnection createconnection ()
{
// Read the database connection string
String strconn = configurationmanager. receivettings ["dbconn"];

Oledbconnection conn = new oledbconnection ();
// Specify the database connection string
Conn. connectionstring = strconn;

// Return to the database connection instance
Return conn;
}

/// <Summary>
/// Create an adapter
/// </Summary>
/// <Param name = "strselect"> SELECT statement </param>
/// <Returns> adapter </returns>
Public static oledbdataadapter createadapter (string strselect)
{
// Create a database connection
Oledbconnection conn = createconnection ();
// Return the adapter
Return new oledbdataadapter (strselect, Conn );
}
}

/// <Summary>
/// Intermediate class
/// </Summary>
Public class UI
{
/// <Summary>
/// Static instance
/// </Summary>
Public static readonly UI normal = new UI ();

/// <Summary>
/// Create a dview instance
/// </Summary>
/// <Returns> datagridview instance </returns>
Public Virtual datagridview creategridview ()
{
Datagridview gridview = new datagridview ();
Gridview. Dock = dockstyle. Fill;
// Display the title line
Gridview. columnheadersvisible = true;
Return gridview;
}
}

/// <Summary>
/// Performance class
/// </Summary>
Public class show: Form
{
/// <Summary>
/// Constructor
/// </Summary>
Public Show ()
{
Dataset DS = new dataset ();
// SELECT statement
String strselect = "select * from rocket where 1 = 1 ";

Oledbdataadapter apdapter = dataservice. createadapter (strselect );
Apdapter. Fill (DS, "Rocket ");
Apdapter. Dispose ();

// Create a dview
Datagridview gridview = UI. Normal. creategridview ();
// Set the data source
Gridview. datasource = Ds;
// Specify the data table name
Gridview. datamember = "Rocket ";
// Add the gridview Control
Controls. Add (gridview );

TEXT = "show data ";
}
}
}

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.