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