WPF in MySQLHelper

the using the System;
 the using the System.Collections.Generic;
 the using the System.Linq;
 the using the System.Text;
 the using System.Threading.Tasks; 

the using the MySql.Data.MySqlClient; 

namespace MySQLHelp 
{ 
    public  class SqlHelper 
    { 
        // server address; port number; Database ; username; password 
        public  static  string connectStr = "" ; 

        // set MySQL connection string 
        public  static  string setMySQLStr ( string IP, string Port, string Database, string user,string password)
        {
            try
            {
                connectStr = "server=" + ip + ";port=" + port + ";database=" + database + ";user=" + user + ";password=" + password + "";
                return "set connStr ok";
            }
            catch(Exception e)
            {
                return e.ToString();
            }
        }

        // a using MySql.Data.MySqlClient;
         // declare conn object is created to facilitate the connection is established 
        public  static the MySqlConnection conn = null ; 

        // establish connection Mysql 
        public  static  String connMysql () 
        { 
            the try 
            { 
                conn = new new the MySqlConnection (connectStr); 
                conn. the Open (); 
                return  " Conn the MySQL OK " ; 
            } 
            the catch (Exception E) 
            { 
                return e.toString (); 
            } 
        }

        //Close Mysql connection 
        public  static  String closedMysql () 
        { 
            the try 
            { 
                conn.Close (); 
                return  " Close the MySQL OK " ; 
            } 
            the catch (Exception E) 
            { 
                return e.toString (); 
            } 
        } 

        // execute SQL statements 
        public  static String excuteSQL ( String STR) 
        { 
            the try 
            { 
                connMysql ();                                             // establish connection MySQL
                Cmd = the MySqlCommand new new the MySqlCommand (STR, Conn);          // perform 
                the MySqlDataReader = cmd.ExecuteReader Reader ();            // read array 
                the while (reader.Read ())                                    // to true indicates able to read the line data 
                {
                     return Reader [ 0 ] .ToString ();                         // for accessing the array 
                } 
                closedMysql ();                                           // Close MySQL connection 
                return  " Qure OK " ; 
            } 
            the catch (Exception e)
            {
                return e.ToString();
            }
        }
    }
}

Guess you like

Origin www.cnblogs.com/shyw/p/12096723.html