. NET connection to the MySQL database

Source: Internet
Author: User

Add reference to MySQLDriverCS. dll,: http://downloads.sourceforge.net/mysqldrivercs/MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe

   1:  using System;
   2:  using System.Web.UI.WebControls;
   3:  using System.Data;
   4:  using MySQLDriverCS;
   5:   
   6:  public partial class _Default : System.Web.UI.Page 
   7:  {
   8:      protected void Page_Load(object sender, EventArgs e)
   9:      {
  10:          MySQLConnection conn = null;
  11:          conn = new MySQLConnection(new MySQLConnectionString("Localhost", "CNPCEdit", "root", "").AsString);
  12:          conn.Open();
  13:          MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
  14:          commn.ExecuteNonQuery();
  15:          string sql = "select * from Checklist where family='Apiaceae'";
  16:          MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
  17:          DataSet ds = new DataSet();
  18:          mda.Fill(ds, "Checklist");
  19:          grdFamily.DataSource = ds;
  20:          grdFamily.DataBind();
  21:          conn.Close();
  22:      }
  23:      protected void grdFamily_PageIndexChanging(object sender, GridViewPageEventArgs e)
  24:      {
  25:          grdFamily.PageIndex = e.NewPageIndex;
  26:      }
  27:  }

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.