mysql - fill a database using data of another database in c# -
i'am working on winform c# , phpmyadmin (database). have 2 differents databases(db1 , db2).
i want fetch data of 1 column of table1 in db1 , store these information in table2 of db2 such if there modifications in column of db1, db2 should automacally updated.
this logic used it's not working:
using mysql.data.mysqlclient; namespace gnms { public partial class doublecoonection : form { dataset ds; mysqldataadapter da1; mysqldataadapter da2; mysqlconnection connec1; //for 1st database mysqlconnection connec2;//for 2nd 1 public doublecoonection() { initializecomponent(); } private void button1_click(object sender, eventargs e) { string str_conn = "server=localhost;username=root;password=****;port=3306"; string query1 = "select id,city enugro.city;"; //query1 1st db connec1 = new mysqlconnection(str_conn); try { connec1.open(); da1 = new mysqldataadapter(query1, connec1);// how stored results of first data in object da connec1.close(); connec2 = new mysqlconnection(str_conn); // open second connection connec2.open(); string query2 = "insert enugro_africa.reports(id,city) value(da1);"; da2 = new mysqldataadapter(query2, connec2);//query 2nd db ds = new dataset();//store in temporarily da2.fill(ds); //fill dataset "ds" datagridview1.datasource = ds;//display result in datagridview } catch(exception ex){ messagebox.show(ex.message); } } }
}
please u me?.
you using disconnected ado.net architecture...that means not have open , close connection...data adapter you. remove code , try again
moreover, query 2 seems incorrect. have call fill of first data adapter fill data set , iterate through data set , call second query pass value want pass.
alternatively, can pass whole data xml stored procedure can bulk insert
Comments
Post a Comment