Asp.net connection to mysql database code

Source: Internet
Author: User

New OdbcConnection connection core code

Private void MainClass_Load (object sender, System. EventArgs e)
{
String connectionString = @ "Driver = {MySQL}; SERVER = localhost; DATABASE = NorthwindMySQL ;";

OdbcConnection conn = new OdbcConnection (connectionString );
Conn. Open ();

OdbcDataAdapter da = new OdbcDataAdapter ("SELECT CustomerID, ContactName, ContactTitle FROM MERs", conn );

DataSet ds = new DataSet ("Cust ");
Da. Fill (ds, "MERs ");

DataGrid1.DataSource = ds. DefaultViewManager;
Conn. Close ();
}

The detailed instance is as follows:

Using System;
Using System. Drawing;
Using System. Collections;
Using System. ComponentModel;
Using System. Windows. Forms;
Using System. Data;
Using Microsoft. Data. Odbc;

Public class MainClass: System. Windows. Forms. Form
{
Private System. Windows. Forms. DataGrid dataGrid1;

Public MainClass ()
{
InitializeComponent ();
}
Private void InitializeComponent ()
{
This. Maid = new System. Windows. Forms. DataGrid ();
(System. ComponentModel. ISupportInitialize) (this. dataGrid1). BeginInit ();
This. SuspendLayout ();
//
// DataGrid1
//
This. dataGrid1.DataMember = "";
This. dataGrid1.HeaderForeColor = System. Drawing. SystemColors. ControlText;
This. Maid = new System. Drawing. Point (0, 8 );
This. Maid = "maid ";
This. dataGrid1.Size = new System. Drawing. Size (376,288 );
This. Maid = 0;
//
// MainClass
//
This. AutoScaleBaseSize = new System. Drawing. Size (5, 13 );
This. ClientSize = new System. Drawing. Size (384,302 );
This. Controls. AddRange (new System. Windows. Forms. Control [] {
This. dataGrid1 });
This. Load + = new System. EventHandler (this. MainClass_Load );
(System. ComponentModel. ISupportInitialize) (this. dataGrid1). EndInit ();
This. ResumeLayout (false );

}
[STAThread]
Static void Main ()
{
Application. Run (new MainClass ());
}

Private void MainClass_Load (object sender, System. EventArgs e)
{
String connectionString = @ "Driver = {MySQL}; SERVER = localhost; DATABASE = NorthwindMySQL ;";

OdbcConnection conn = new OdbcConnection (connectionString );
Conn. Open ();

OdbcDataAdapter da = new OdbcDataAdapter ("SELECT CustomerID, ContactName, ContactTitle FROM MERs", conn );

DataSet ds = new DataSet ("Cust ");
Da. Fill (ds, "MERs ");

DataGrid1.DataSource = ds. DefaultViewManager;
Conn. Close ();
}
}

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.