. NET connection to MySQL and SQL Server databases

Source: Internet
Author: User

To connect to MySQL:

First, we need to download a package and unzip "MySql.Data.dll", click Download

Using MySql.Data.MySqlClient;
 mysqlconnection mycon = new Mysqlconnection ("Server=xxx.xxx.xx.xxx;user Id=sa;password=sa;database=wan"); mycon . Open (); Mysqlcommand mysqlcom = new Mysqlcommand ("Select Password_ from the person where username= '" + Username + "'", mycon); Mysqldataadapter SDA = new Mysqldataadapter (); SDA. SelectCommand = Mysqlcom;dataset ds = new DataSet (); SDA. Fill (DS); string password_ = null;try{Password_ = ds. Tables[0]. rows[0]["Password_"]. ToString ();} catch{return "The account is not registered";} try{if (password_.    Equals (Password)) {return "account and password are correct";    } else {return "password error"; }}finally{mysqlcom.    Dispose (); Mycon.    Dispose (); Mycon. Close ();} 

Connecting to SQL Server:

SqlConnection mycon = new SqlConnection ("server=.; Database=wan;uid=sa;pwd=sa "); con. Open (); SqlCommand sqlcom = new SqlCommand ("Select Password_ from the person where username= '" + Username + "'", con); SqlDataAdapter SDA = new SqlDataAdapter (); SDA. SelectCommand = Sqlcom;dataset ds = new DataSet (); SDA. Fill (DS); string password_ = null;try{    Password_ = ds. Tables[0]. rows[0]["Password_"]. ToString ();} catch{    Return "The account is not registered";} try{    if (password_. Equals (Password))    {        return "account and password are correct";    }    else    {        return ' password error ';    }} finally{    sqlcom. Dispose ();    Con. Dispose ();    Con. Close ();}    


. NET connection to MySQL and SQL Server databases

Related Article

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.