private int DDL_Operation_Table(ref DataTable dt, ref string select_Result, string source_DBName, string dest_DBName, string dest_DBName_f) { int i = -1; //string getDBInfoToStore_Table = "[]"; string generateScriptToStore_Table = "[SP_Dey_CreateTableScriptMain]"; //SQLServerDBHelper.GenerateScriptToStore(source_DBName, dest_DBName, getDBInfoToStore_Table); //获得定义的信息,存入配置库 //txbResult.AppendText("表:取“" + source_DBName_f + "”中表的定义信息,并存入“" + dest_DBName_f + "”的操作成功\r\n\r\n"); txbResult.AppendText("操作比较多!请稍等,让它跑一会!\r\n\r\n"); string log_Information = SQLServerDBHelper.GetTableInfoToStore(source_DBName, dest_DBName, generateScriptToStore_Table);//生成创建元数据的脚本 string[] log_Information_new = log_Information.Split(new char[] { '@' }); for (int j = 0; j < log_Information_new.Length - 1; j++) { txbResult.AppendText("表:" + log_Information_new[j] + "\r\n\r\n"); } //创建SQL文件夹 string fp = "d:\\SQL\\" + DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月"; Directory.CreateDirectory(fp); DirectoryInfo dir = new DirectoryInfo(fp); if (!File.Exists(fp)) { dir.Create(); } string str_Type = "T,M,N,A,S,R,L"; string str_FileName = "Table"; select_Result = ""; string[] str_type_new = str_Type.Split(new char[] { ',' }); string dateTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); string filePath = fp + @"\" + str_FileName + "_" + dest_DBName_f + "_" + dateTime + ".sql";//定义文件名 for (int k = 0; k < str_type_new.Length; k++) { //把数据库中的数据存入文件中 dt.Clear(); dt = SQLServerDBHelper.GetInfoStoreFile(str_type_new[k]); txbResult.AppendText("表:获取数据库中" + str_type_new[k] + "类型的数据成功\r\n\r\n"); for (i = 0; i < dt.Rows.Count; i++)//取出的数据连成字符串 { select_Result += dt.Rows[i][0].ToString(); txbResult.AppendText("表:获取的" + str_type_new[k] + "类型数据转换成功\r\n\r\n"); if (!File.Exists(filePath)) { FileStream fs = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read); StreamWriter sw = new StreamWriter(fs);//写入文件中 fs.SetLength(0); sw.WriteLine(select_Result); sw.Close(); } else { FileStream fst = new FileStream(filePath, FileMode.Open, FileAccess.Write, FileShare.Read); StreamWriter swt = new StreamWriter(fst); fst.SetLength(0); swt.WriteLine(select_Result); swt.Close(); } } txbResult.AppendText("表:" + str_type_new[k] + "类型的数据存储完成\r\n\r\n"); } txbResult.AppendText("表:文件存储的完整路径:" + filePath + "\r\n\r\n"); txbResult.AppendText("表:所以数据存储完成\r\n\r\n"); return(i); }