| 发表于:2007-03-02 17:24:15 楼主 |
我是想从一台sql服务器上导到别一台服务器上数据量很大.请各位多多指点呀.在线急等. namespace windowsapplication4 { public partial class daoru : form { public string connstr2 =@ "server=127.0.0.1;uid=sa;pwd=1234ee;database=ewer; ";//本地服务器 public string connstr = @ "server=badsf;uid=sa;pwd=2123123;database=werwe; ";//远程服务器数据源 public string cladd= " "; public daoru() { initializecomponent(); } private void button2_click(object sender, eventargs e) { string testsql= " "; string strins2= " "; string top2 = " "; if (textbox1.text.tostring() != "0 " && textbox1.text.tostring() != " ") { top2 = @ " top " + textbox1.text.tostring(); if (combobox1.text.tostring() == "hy ") { testsql = @ "select " + top2 + " * from [smss_sendmsg] where convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120) and 信息分类= 'hy ' "; strins2 = @ "insert into info_cat (title,add1,add2,tel,st_date,adddate,end_date,audit,upclass,cont,userid,cat_class) values "; cladd = "info_cat "; } if (combobox1.text.tostring() == "hy ") { testsql = @ "select "+top2+ " * from [smss_sendmsg] where convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120) and 信息分类= 'hy ' "; strins2 = @ "insert into info_goods (title,add1,add2,tel,sg_date,senddate,enddate,audit,upclass,cont,userid) values "; cladd = "info_goods "; } daoru5(testsql, strins2, connstr, connstr2); } else { messagebox.show( "最大导入量不能为0或为空! "); } } private void button1_click(object sender, eventargs e) { string testsql = @ "select * from [smss_sendmsg] where convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120) "; gu(testsql,connstr); } public void gu(string strf, string odb) { try { listbox1.items.clear(); sqlconnection connf = new sqlconnection(); connf.connectionstring = @odb; sqldataadapter myadapter = new sqldataadapter(); connf.open(); sqlcommand sqlcommand = new sqlcommand(strf, connf); sqlcommand.connection = connf; sqldatareader readdata = null; readdata=sqlcommand.EXECutereader(); messagebox.show(connf.state.tostring()); int i = 0; while(readdata.read()==true) { label1.text = @readdata[ "信息 "].tostring(); label5.text = i.tostring(); listbox1.items.add(readdata[ "编号 "].tostring() + readdata[ "信息 "].tostring() + readdata[ "出发地 "].tostring() + readdata[ "来源 "].tostring() + " 发布时间: " + readdata[ "发送时间1 "].tostring() + "电话: " + readdata[ "电话号码 "].tostring()); label5.refresh(); label1.refresh(); i = i + 1; } connf.close(); } catch (exception e) { messagebox.show(e.tostring()); } } public void daoru5(string strf,string strins, string odb,string odb2) { try { listbox1.items.clear(); sqlconnection connf = new sqlconnection(); connf.connectionstring = @odb; sqldataadapter myadapter = new sqldataadapter(); connf.open(); sqlcommand sqlcommand = new sqlcommand(strf, connf); sqlcommand.connection = connf; sqldatareader readdata = null; readdata = sqlcommand.EXECutereader(); int i = 0; sqlconnection connf2 = new sqlconnection(); connf2.connectionstring = odb2; while (readdata.read() == true) { connf2.open(); string strins2; if (combobox1.text.tostring() == "hy ") { strins2 = strins + @ "( ' " + readdata[ "信息 "].tostring() + " ', ' " + readdata[ "出发地 "].tostring() + " ', ' " + readdata[ "出发地 "].tostring() + " ', ' " + readdata[ "电话号码 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ',1,2, ' " + readdata[ "信息 "].tostring() + " ', ' " + combobox3.text.tostring() + " ') "; } else { system.random r = new random(); int yourandom = r.next(1, 4); strins2 = strins + @ "( ' " + readdata[ "信息 "].tostring() + " ', ' " + readdata[ "出发地 "].tostring() + " ', ' " + readdata[ "出发地 "].tostring() + " ', ' " + readdata[ "电话号码 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ', ' " + readdata[ "发送时间1 "].tostring() + " ',1,2, ' " + readdata[ "信息 "].tostring() + " ', ' " + combobox3.text.tostring() + " ', " + yourandom.tostring()+ ") "; } sqlcommand inst2 = new sqlcommand(strins2, connf2); inst2.EXECutenonquery(); label1.text = @readdata[ "信息 "].tostring(); listbox1.items.add(readdata[ "编号 "].tostring() + readdata[ "信息 "].tostring() + readdata[ "出发地 "].tostring() + readdata[ "来源 "].tostring() + " 发布时间: " + readdata[ "发送时间1 "].tostring() + "电话: " + readdata[ "电话号码 "].tostring()); listbox1.refresh(); label5.text = i.tostring(); label5.refresh(); label1.refresh(); i = i + 1; } connf2.close(); } connf.close(); messagebox.show( "导入成功! "); } catch (exception e) { messagebox.show(e.tostring()); } } } } |
|
|
|
|