10,对源库操作,对目标库操作
////// 对源库操作 /// /// /// private DataTable IsOpenDT(string strSQL, string strConn) { SqlConnection hipiscon; SqlCommand SQLcom; DataTable DT; SqlDataAdapter SQLADA; hipiscon = new SqlConnection(strConn); SQLcom = new SqlCommand(strSQL, hipiscon); try { hipiscon.Open(); SQLcom.ExecuteNonQuery(); conYes = true; hipiscon.Close(); } catch (Exception ex) { conYes = false; fslog(ex); //Thread.Sleep(300000); } DT = new DataTable(); SQLADA = new SqlDataAdapter(SQLcom); SQLADA.Fill(DT); return DT; } ////// 对目标库操作 /// /// /// private void IsOpen(string strsql, string strconn) { try { SqlConnection pregcon = new SqlConnection(strconn); SqlCommand sqlcom = new SqlCommand(strsql, pregcon); pregcon.Open(); sqlcom.ExecuteNonQuery(); conYes = true; pregcon.Close(); } catch (Exception ex) { conYes = false; fslog(ex); //Thread.Sleep(300000); } }
11,具体操作方法
////// /// /// /// /// /// private void DoWork_select() { //string strtb = System.Configuration.ConfigurationManager.AppSettings["strtable"].ToString(); //string strupdt = System.Configuration.ConfigurationManager.AppSettings["updt"].ToString(); //string strwhere = System.Configuration.ConfigurationManager.AppSettings["where"].ToString(); while (tureOfalse) { ISopenCon(); /*2015/2/2 调整:不能把菜单全部删除,没有的添加到服务器上去,已存在的过滤掉*/ //DelPreg(); //DataTable dt = IsOpenDT(strSQL, strdbHipis); //String[] tablenamekey = new String[3] { "dbo.sys_Menu", "dbo.sys_MenuInRoles", "dbo.sys_UsersInRoles" };//源数据库 //String[] tablenamekeypreg = new String[3] { "dbo.sys_Menu_Copy", "dbo.sys_MenuInRoles_Copy", "dbo.sys_UsersInRoles_Copy" };//目标数据库 //测试数据 String[] tablenamekey = new String[1] { "dbo.sys_Menu" };//源数据库 String[] tablenamekeypreg = new String[1] { "dbo.sys_Menu_Copy" };//目标数据库 if (tablenamekey.Length > 0) { for (int i = 0; i < tablenamekey.Length; i++) { string strtablenamekey = tablenamekey[i]; string strSQL1 = "select * from "; strSQL1 += strtablenamekey; strSQL1 += " where (1=1)"; insert_OR_update(strdbHipis, ref strSQL1, tablenamekeypreg[i]); } } } } ////// 插入,更新 最新数据到PIS数据库 /// /// 需要更新的表的连接字符串 /// 最后SQL语句 /// 需要操作的表 private void insert_OR_update(string strdbHipis, ref string strSQL, string tbName) { int a = 0; int b = 0; string lastSQL; DataTable dttb; DataTable dttb1; dttb = IsOpenDT(strSQL, strdbHipis); /*2015/2/2 调整:新增[进度条]追加显示加载信息*/ progressBar1.Maximum = dttb.Rows.Count;//设置最大长度值 progressBar1.Value = 0;//设置当前值 progressBar1.Step = 1;//