/// <summary> /// Establishes a connection. /// </summary> /// <param name="connect">Optional.</param> public Connection(string connect = "server=localhost;port=3306;userid=root;database=currency_converter;password=;sslmode=None") { //value[0] = "server=localhost"; //value[1] = "database=patho"; ///value_2[0] = "server"; ///value_2[1] = "localhost"; /// ///value-2[1][0] = "database"; ///value-2[1][1] = "patho"; Filter f = new Filter(); string extras = ""; //LETS CHECK IF THE USER INPUTED A DATABASE IN THE CONNECT STRING ALREADY, SO WE DON'T NEED TO ADD IT if (f.Search(connect, "database=") == true) {//the user altered the initial value, so no need to add the database again //check for the database value to be able to set the global db variable to what was entered.and also //so that the ChooseDB() method can have effect on this too. :) Split p = new Split(); Split joiner = new Split(); string sep = ""; p.Divide(connect, ';'); Split c = new Split(); //now loop through the array, since we've plit the connect string for (int i = 0; i < p.Value_array.Length; i++) { //now split again, this time, with equal to"=", so that we get the value if (p.Value_array[i].Trim() == "") { //do nothing } else { c.Divide(p.Value_array[i], '='); //loop again to locate the database value for (int j = 0; j < c.Value_array.Length && c.Value_array.Length > 1; j++) { // the array list must be at least 2 if (c.Value_array[j] == "database") { //we've found it, get the value //since the "=" is used , it'll probably be 'database=value',so database is c.Value_array[0], //then the value is c.Value_array[1]; //so store the value in the global value (App.Current as App).Db_name = c.Value_array[1]; //set the global db var to the database value so that when it's changed, it can work. c.Value_array[1] = this.database; //lets pack up everything, we opened, operated, now we're closing up. // break; } else /* do nothing */ } { //check if its the last value int calc = c.Value_array.Length - j; if (calc == 1) {//it's the last value sep = ""; } else { sep = "="; } //extras += c.Value_array[j] + sep; extras = joiner.Join(c.Value_array, '='); } p.Value_array[i] = extras; } } //join back con_string = joiner.Join(p.Value_array, ';'); } else { con_string = connect + ";database=" + this.Database; } //SET THE CONNECTION // MySqlConnection con = new MySqlConnection(this.con); this.con.ConnectionString = @con_string; }