//Creates the db in ->...\source\repos\Company\Company\bin\Debug public Boolean CreateDB() { Boolean result = false; try { ADOX.Catalog cat = new ADOX.Catalog(); String File = "Master.mdb"; cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + File + ";" + "Jet OLEDB:Engine Type=5"); MessageBox.Show("Database Created Successfully ...\\source\\repos\\Company\\Company\\bin\\Debug"); OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Master.mdb"); con.Open(); string strTemp = " [Id] Number, [FirstName] Text, [LastName] Text, [BirthDate] Text "; OleDbCommand com = new OleDbCommand(); com.Connection = con; com.CommandText = "CREATE TABLE Employees(" + strTemp + ")"; com.ExecuteNonQuery(); com.Connection.Close(); con.Close(); cat = null; result = true; }catch (Exception ex) { result = false; } return(result); }
// Create DB method public static void DBCreate() { if (File.Exists(DBFileName)) { Console.WriteLine("BD file is already exists. No need to create "); } else { Console.WriteLine("DB file does not exist. Creating a DB file"); ADOX.Catalog cat = new ADOX.Catalog(); try { // Name and source of MDB file cat.Create("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + DBLocationPath + DBFileName); // Source=D:\\db_graph.mdb or other location Console.WriteLine("BDCreate succeeded! "); } catch (System.Runtime.InteropServices.COMException Ex) { Console.WriteLine("BDCreate error: " + Ex); cat = null; } DBConnect(); DBStructCreate(); } }
private bool createDB() { bool isres = false; ADOX.Catalog cat = new ADOX.Catalog(); try { dbName = getDBName(); pathToDb = txtPathToDB.Text + $@"{dbName}"; connString = $@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={pathToDb}; Jet OLEDB:Engine Type=5"; cat.Create(connString); OleDbConnection con = cat.ActiveConnection as OleDbConnection; if (con != null) { con.Close(); } isres = true; } catch (Exception ex) { MessageBox.Show(ex.Message); isres = false; } cat = null; return(isres); }
private void napravi_novu_datoteku(object sender, EventArgs e) { Save.ShowDialog(); cur_open_file = Save.FileName + ".tocke"; this.Text = cur_open_file; try { ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbpath); cat = null; System.IO.File.Copy(dbpath, cur_open_file, true); } catch (Exception ee) { if (ee.ToString() != "1") { if (Debug) { MessageBox.Show("Spremi staru datoteku"); } spremiKaoToolStripMenuItem.PerformClick(); File.Delete(dbpath); ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbpath); cat = null; System.IO.File.Copy(dbpath, cur_open_file, true); } } Osvjezi.PerformClick(); }
public bool CreateDatabase() { bool result = false; ADOX.Catalog cat = new ADOX.Catalog(); try { string connection = this.GetConnectionString(); cat.Create(connection); Table assignment = this.CreateAssignmentTable(cat); cat.Tables.Append(assignment); Table folders = this.CreateFoldersTable(cat); cat.Tables.Append(folders); Table image = this.CreateImageTable(cat); cat.Tables.Append(image); //Now Close the database ADODB.Connection con = cat.ActiveConnection as ADODB.Connection; if (con != null) { con.Close(); } result = true; } catch (Exception ex) { result = false; } cat = null; return(result); }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static bool CreateNewAccessDatabase(string fileName) { bool result = false; ADOX.Catalog cat = new ADOX.Catalog(); //ADOX.Table table = new ADOX.Table(); //Create the table and it's fields. //table.Name = "Table1"; //table.Columns.Append("Field1"); //table.Columns.Append("Field2"); try { cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + "; Jet OLEDB:Engine Type=5"); //cat.Tables.Append(table); //Now Close the database ADODB.Connection con = cat.ActiveConnection as ADODB.Connection; if (con != null) { con.Close(); } result = true; } catch (Exception) { result = false; } cat = null; return(result); }
public void DtaDbCre() { if (!File.Exists(@"Data\Data.accdb")) { ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table table = new ADOX.Table(); try { cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Data\\Data.accdb; Jet OLEDB:Engine Type=5"); //Now Close the database ADODB.Connection con = cat.ActiveConnection as ADODB.Connection; if (con != null) { con.Close(); } //result = true; } catch //(Exception ex) { } cat = null; TblCre(); } //End if } //End dbCre
private void _InitSqlLst() { // if (queryLst != null) { return; } if (con == null) { throw new InvalidOperationException(); } var querylst = new List <string>(); string s; var cat = new ADOX.Catalog(); var cmd = new ADODB.Command(); queryLst = new List <Query>(); //アクションクエリ var rs = con.OpenSchema(ADODB.SchemaEnum.adSchemaProcedures); while (!rs.EOF) { s = rs.Fields["PROCEDURE_NAME"].Value.ToString(); rs.MoveNext(); if (!s.StartsWith("~")) { querylst.Add(s); } } cat.ActiveConnection = con; foreach (var q in querylst) { // cmd = (ADODB.Command)cat.Procedures[q].Command; var sql = cmd.CommandText.ToUpper(); //var name = cmd.Name; var name = q; if (!(sql.StartsWith("UPDATE") || sql.StartsWith("INSERT"))) { return; } var query = new Query(name, sql); queryLst.Add(query); //if (sql.StartsWith("UPDATE")) // updateSqlLst.Add(sql); //if (sql.StartsWith("INSERT")) // insertSqlLst.Add(sql); } }
public void Creat() { string app_path; app_path = Application.StartupPath + "\\Manager.mdb"; ADOX.Catalog catalog = new ADOX.Catalog(); catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + app_path + ";Jet OLEDB:Engine Type=5"); }
static void Main(string[] args) { string username = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); if (File.Exists(username + @"\Documents\H.T I.R Aide\Notes\NewMDB.accdb")) { File.Delete(username + @"\Documents\H.T I.R Aide\Notes\NewMDB.accdb"); } ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table table = new ADOX.Table(); table.Name = "Overview"; table.Columns.Append("Offense Type"); table.Columns.Append("Total Notes"); table.Columns.Append("Percent of Notes"); table.Columns.Append("Number tagged as Closed"); DataTable test = new DataTable(); test.NewRow(); DataColumn column; DataRow row; column = new DataColumn(); column.ColumnName = "id"; test.Columns.Add(column); column = new DataColumn(); column.ColumnName = "hi"; test.Columns.Add(column); ArrayList hi = new ArrayList(); for (int i = 0; i < 10; i++) { row = test.NewRow(); row["id"] = i; row["hi"] = i + 1; test.Rows.Add(row); hi.Add(row["id"] + " " + row["hi"]); WriteLine(row["id"] + " " + row["hi"]); } string[] nope = new string [hi.Count]; hi.CopyTo(nope); File.WriteAllLines(username + @"\Documents\H.T I.R Aide\Notes\testNewMDB.accdb", nope); cat.Create("Provider =Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + username + @"\Documents\H.T I.R Aide\Notes\NewMDB.accdb; " + "Jet OLEDB:Engine Type=5"); cat.Tables.Append(table); WriteLine("Database Created Successfully"); ReadKey(); cat = null; }
//创建数据库 public void createDb(String versionNum) { ADOX.Catalog catalog = new ADOX.Catalog(); //String versionNum = extension.Text; try { catalog.Create(databaseCon + otherDbs + versionNum + ".mdb" + ";Jet OLEDB:Engine Type=5"); } catch { } ADODB.Connection cn = new ADODB.Connection(); cn.Open(databaseCon + otherDbs + versionNum + ".mdb", null, null, -1); catalog.ActiveConnection = cn; //创建表 ADOX.Table table = new ADOX.Table(); table.Name = "config1"; //创建列 ADOX.Column column = new ADOX.Column(); column.ParentCatalog = catalog; column.Name = "ID"; column.Type = DataTypeEnum.adInteger; column.DefinedSize = 9; column.Properties["AutoIncrement"].Value = true; table.Columns.Append(column, DataTypeEnum.adInteger, 9); // 设置为主键 table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column, null, null); table.Columns.Append("fileName", DataTypeEnum.adVarWChar, 0); table.Columns.Append("fileSize", DataTypeEnum.adInteger, 0); table.Columns.Append("createTime", DataTypeEnum.adDate, 0); table.Columns.Append("modifiedTime", DataTypeEnum.adDate, 0); table.Columns.Append("path", DataTypeEnum.adLongVarWChar, 0); table.Columns.Append("versionNum", DataTypeEnum.adInteger, 0); table.Columns.Append("updateMethod", DataTypeEnum.adVarWChar, 0); try { // 添加表 catalog.Tables.Append(table); } catch (Exception ex) { MessageBox.Show(ex.Message); } //此处一定要关闭连接,否则添加数据时候会出错 table = null; catalog = null; //Application.DoEvents(); cn.Close(); }
static void Main(string[] args) { ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;"); Console.WriteLine("Database Created Successfully"); cat = null; }
//tests public static void RunAdoxAdorTest() { try { ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table tab = new ADOX.Table(); _msg.Length = 0; _msg.Append("RunAdoxAdorTest started ..."); Program._messageLog.WriteLine(_msg.ToString()); tab.Name = "TestTab1"; tab.Columns.Append("PK1", ADOX.DataTypeEnum.adInteger); tab.Columns.Append("F1", ADOX.DataTypeEnum.adVarWChar, 30); tab.Columns.Append("F2", ADOX.DataTypeEnum.adDouble); tab.Columns.Append("F3", ADOX.DataTypeEnum.adVarBinary); tab.Columns.Append("F4", ADOX.DataTypeEnum.adBoolean); tab.Columns.Append("F5", ADOX.DataTypeEnum.adCurrency); tab.Columns.Append("F6", ADOX.DataTypeEnum.adWChar); tab.Columns.Append("F7", ADOX.DataTypeEnum.adSmallInt); tab.Columns.Append("F8", ADOX.DataTypeEnum.adSingle); //tab.Columns.Append("F9", ADOX.DataTypeEnum.adDecimal,18); //invalid, use double instead tab.Columns.Append("F9", ADOX.DataTypeEnum.adLongVarBinary); tab.Columns.Append("F10", ADOX.DataTypeEnum.adLongVarWChar); tab.Columns.Append("F11", ADOX.DataTypeEnum.adBoolean); tab.Columns.Append("F12", ADOX.DataTypeEnum.adVarWChar, 1); tab.Columns.Append("F13", ADOX.DataTypeEnum.adUnsignedTinyInt); tab.Columns.Append("F14", ADOX.DataTypeEnum.adDate); //if (File.Exists(@"C:\Testfiles\Access\NewMDB.mdb")) // File.Delete(@"C:\Testfiles\Access\NewMDB.mdb"); //cat.Create(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Testfiles\Access\NewMDB.mdb;User Id=admin;Password=;Jet OLEDB:Engine Type=5"); if (File.Exists(@"C:\Testfiles\Access\NewMDB.accdb")) { File.Delete(@"C:\Testfiles\Access\NewMDB.accdb"); } cat.Create(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Testfiles\Access\NewMDB.accdb;User Id=admin;Password=;Jet OLEDB:Engine Type=6"); cat.Tables.Append(tab); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { _msg.Length = 0; _msg.Append("... RunAdoxAdorTest finished."); Program._messageLog.WriteLine(_msg.ToString()); } }
public string CreateDb() { ADOX.Catalog cat = new ADOX.Catalog(); string tempFile = Path.GetTempFileName(); File.Delete(tempFile); cat.Create(BuildQueryString(tempFile)); cat.ActiveConnection.Close(); return(tempFile); }
private void otvori_dat(object sender, EventArgs e) { if (sender.ToString() == "Otvori") { Open.ShowDialog(); cur_open_file = Open.FileName; System.IO.File.Copy(cur_open_file, dbpath, true); this.Text = cur_open_file; } //MessageBox.Show(Open.FileName + "\n\n" + Application.StartupPath); if (!File.Exists(dbpath)) { ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbpath); cat = null; } conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbpath); //adapter.Fill(medataset); try { using (OleDbCommand cmd = new OleDbCommand(global::Interpolator.Properties.Resources.PropertiesCreateString, conn)) { conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } catch (Exception ee) { if (Debug) { MessageBox.Show("Error: " + ee.ToString()); } } medataset = new DataSet(); OleDbCommand cmd1 = new OleDbCommand(selekt, conn); adapter = new OleDbDataAdapter(cmd1); adapter.Fill(medataset); for (int i = 0; i < this.Controls.Count; i++) { if (this.Controls[i].GetType().ToString() == "System.Windows.Forms.Panel" && this.Controls[i].Name != "SkupFunkcija") { this.Controls[i].Dispose(); i--; } } br_tablica = 0; updatezy(); }
public bool CreateDatabaseFile() { if (this.DirectoryExists()) { var cat = new ADOX.Catalog(); cat.Create(string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5", this.CompleteFileString())); cat = null; } return false; }
/// <summary> /// 判断表是否存在 /// </summary> /// <param name="_TableName">表名</param> /// <param name="_Catalog">数据库对象</param> /// <param name="_Connection">数据库连接信息</param> /// <returns>False存在;True不存在</returns> private bool TableExist(string _TableName, ADOX.Catalog _Catalog, ADODB.Connection _Connection) { if (_Catalog.Tables.Count > 0) { for (int i = 0; i < _Catalog.Tables.Count; i++) { if (_Catalog.Tables[i].Name == _TableName) { return(false); } } } return(true); }
/// <summary> /// 动态创建ACCESS /// </summary> /// <returns></returns> public bool CreateAccess() { try { ADOX.Catalog catalog = new ADOX.Catalog(); catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbPath + ";Jet OLEDB:Engine Type=5"); return(true); } catch (Exception ex) { _strErrorInfo = ex.Message; return(false); } }
} // end InsertOrderItem public static void ConstructDatabase() { // Microsoft advise that ADOX class is not tested. It is used here only to create a database ADOX.Catalog cat = new ADOX.Catalog(); // Create Database if it does not exists if (!File.Exists(dbFolder + "BurgerDB.mdb")) { cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + dbFolder + "BurgerDB.mdb;" + "Jet OLEDB:Engine Type=5"); MessageBox.Show("Database Created Successfully"); } else { MessageBox.Show("Database already exists at " + dbFolder); } // Create tables conn.Open(); // Do not use possible SQL keywords in table names, field names. // OleDbCommand cmd1 = new OleDbCommand("CREATE TABLE test1 (Name varchar(50), Quantity integer)", conn); // works string cmdString = " CREATE TABLE OrderItem (Name varchar(50), TypeName varchar(50), ISize varchar(10), BaseCost decimal, Quantity int)"; // + OleDbCommand cmd1 = new OleDbCommand(cmdString, conn); try // Ceeate the database table if it does not exist { // Now lets execute the SQL ;D cmd1.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show(e.Message); } // Insert data to table // InsertOrderItem(conn, out cmdString, out cmd1); conn.Close(); cat = null; } // end of ConstructDatabase
/// <summary> /// Создание Базы данных /// </summary> public static void add() { try { ADOX.Catalog k = new ADOX.Catalog(); k.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\BD\\New_BD_mass1.mdb"); MessageBox.Show("БД Создана"); } catch (System.Runtime.InteropServices.COMException sit) { MessageBox.Show(sit.Message); } }
public void Connect(string path) { var binFolderPah = path;//获取文件夹绝对路径,.mdb文件在此文件夹下 var Databasepath = new ADOX.Catalog(); connectionString = binFolderPah;// filecheck = File.Exists(binFolderPah); if (!File.Exists(binFolderPah)) { SQLiteConnection.CreateFile(connectionString); } db = new SQLiteConnection("Data source=" + connectionString); db.Open(); }
private void ClearTempDB() { var storageDbCatalog = new ADOX.Catalog(); var tempDBConnection = new ADODB.Connection(); tempDBConnection.Open(masterConnString); storageDbCatalog.ActiveConnection = tempDBConnection; List <string> tableNames = FunRepository.GetOleDbSchema(accessStorageDbPath); foreach (string currentTableName in tableNames) { storageDbCatalog.Tables.Delete(currentTableName); } tempDBConnection.Close(); }
/// <summary> /// Creating mdb file /// </summary> /// <param name="filename">the name of file</param> private static void CreateAccessDatabase(string filename) { string path = Directory.GetCurrentDirectory(); if (!Directory.Exists(Directory.GetCurrentDirectory())) Directory.CreateDirectory(path); ADOX.Catalog database = new ADOX.Catalog(); try { database.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + @"\" + filename + ".mdb; Jet OLEDB:Engine Type=5"); } catch (Exception e) { MessageBox.Show(e.Message); } database = null; }
}// end of function public void MDBCreate() { string DBPath; DBPath = "C:\\Users\\CaptiveIT1\\Documents\\Temp\\MC.mdb"; // create DB via ADOX if not exists if (!System.IO.File.Exists(DBPath)) { //DeleteMDB(); //if (System.IO.File.Exists(DBPath + "\\MC.mdb")) //System.IO.File.Delete(DBPath + "\\MC.mdb"); ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBPath); //cat = null; } } // end of function
public Boolean CreateAccessDatabase() { bool result = false; ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table table = new ADOX.Table(); //Create the table and it's fields. table.Name = "UserInfo"; table.Columns.Append("username", ADOX.DataTypeEnum.adVarWChar, 40); table.Columns.Append("password", ADOX.DataTypeEnum.adVarWChar, 40); table.Columns.Append("age", ADOX.DataTypeEnum.adInteger, 2); table.Columns.Append("gender", ADOX.DataTypeEnum.adVarWChar, 6); table.Columns.Append("occupation", ADOX.DataTypeEnum.adVarWChar, 40); table.Columns.Append("income", ADOX.DataTypeEnum.adDouble, 10); table.Keys.Append("Primary Key", ADOX.KeyTypeEnum.adKeyPrimary, "password", "", ""); try { cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=C:\Users\Umer\Documents\Visual Studio 2015\Projects\masterpage\" + "UserInfo.mdb" + "; Jet OLEDB:Engine Type=5"); //cat.Columns.Append("col1", DataTypeEnum.adInteger, 4); cat.Tables.Append(table); //Now Close the database ADODB.Connection con = cat.ActiveConnection as ADODB.Connection; if (con != null) { con.Close(); } result = true; } catch (Exception ex) { Console.WriteLine(ex); // Namebox.Text = ex.ToString(); result = false; } cat = null; return(result); }
static void CreateNewDatabase() { ADOX.Catalog cat = new ADOX.Catalog(); string tmpStr; string filename = @"C:\LocalDatabase.accdb"; tmpStr = "Provider=Microsoft.Jet.OLEDB.4.0;"; tmpStr += "Data Source=" + filename + ";Jet OLEDB:Engine Type=5"; cat.Create(tmpStr); Table table = new Table(); table.Name = "Main"; table.Columns.Append("NObjednavky", ADOX.DataTypeEnum.adInteger); table.Columns.Append("STAV", ADOX.DataTypeEnum.adBoolean); table.Columns.Append("Cena", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Dobirka", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Firma", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Jmeno", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Adresa", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("PSC", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Mesto", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Vaha", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Sluzby", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("V_symbol", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Telefon", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Email", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Doprava", ADOX.DataTypeEnum.adVarWChar); table.Columns.Append("Vzkaz", ADOX.DataTypeEnum.adLongVarWChar); cat.Tables.Append(table); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(table); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.Tables); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.ActiveConnection); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat); cat = null; }
private void Init() { ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table customersTable = new ADOX.Table(); customersTable.Name = "customers"; customersTable.Columns.Append("customerId", ADOX.DataTypeEnum.adVarWChar, 255); customersTable.Columns.Append("customerName", ADOX.DataTypeEnum.adVarWChar, 255); customersTable.Columns.Append("flightId", ADOX.DataTypeEnum.adVarWChar, 255); ADOX.Table flightsTable = new ADOX.Table(); flightsTable.Name = "flights"; flightsTable.Columns.Append("flightId", ADOX.DataTypeEnum.adVarWChar, 255); flightsTable.Columns.Append("airlineCompany", ADOX.DataTypeEnum.adVarWChar, 255); flightsTable.Columns.Append("origin", ADOX.DataTypeEnum.adVarWChar, 255); flightsTable.Columns.Append("destination", ADOX.DataTypeEnum.adVarWChar, 255); flightsTable.Columns.Append("flightDate", ADOX.DataTypeEnum.adVarWChar, 255); cat.Create(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataSource); cat.Tables.Append(customersTable); cat.Tables.Append(flightsTable); }
public static bool ExportAccessDb(String fileName, DataSet ds) { bool result = false; ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table table = new ADOX.Table(); try { cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + "; Jet OLEDB:Engine Type=5"); //create tables for (int i = 0; i < ds.Tables.Count; i++) { var ctTable = ds.Tables[i]; //Create the table and it's fields. table.Name = ctTable.TableName; CreateAccessCols(table, ctTable); cat.Tables.Append(table); }//end method //now close the database ADODB.Connection conn = cat.ActiveConnection as ADODB.Connection; if (conn != null) conn.Close(); result = true; } catch (Exception ex) { result = false; } cat = null; FillAccessDb(fileName, ds); return result; }//end method
void Timer1Tick(object sender, EventArgs e) { timer1.Stop(); //остановка таймера //определяем расположение программы (путь) ClassConfig.Rapid_ProgramPath = Environment.CurrentDirectory + "\\"; //расположение папки ресурсов ClassConfig.Rapid_Resource = ClassConfig.Rapid_ProgramPath + "resource"; //Проверка существования папки if(!Directory.Exists(ClassConfig.Rapid_Resource)){ //папки нет, она будет создана заново Directory.CreateDirectory(ClassConfig.Rapid_Resource); } //поиск локальной базы данный (список серверов) ClassConfig.Rapid_FileListBase = ClassConfig.Rapid_Resource + "\\list.mdb"; if(!File.Exists(ClassConfig.Rapid_FileListBase)){ //файл не найден, он будет создан ADOX.Catalog ADOXCatalog = new ADOX.Catalog(); try{ ADOXCatalog.Create(ClassConfig.ConnectLineBegin + ClassConfig.Rapid_FileListBase + ClassConfig.ConnectLineEnd + ClassConfig.ConnectPass); //Создание базы данных и таблицы подключений. OleDbConnection OleDb_Connection = new OleDbConnection(); OleDbCommand OleDb_Command; String SQLFullCommand = ""; String SQLCommand = ""; OleDb_Connection.ConnectionString = ClassConfig.ConnectLineBegin + ClassConfig.Rapid_FileListBase + ClassConfig.ConnectLineEnd + ClassConfig.ConnectPass; OleDb_Connection.Open(); //соединение с базой //Создаем таблицу SQLCommand = "CREATE TABLE ListBase ([ID_ListBase] COUNTER PRIMARY KEY, "; SQLFullCommand += SQLCommand; SQLCommand = "[Name] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[Server] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[DataBase] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[Uid] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[Pwd] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[Admin] VARCHAR DEFAULT " + "\"" + "\"" + ", "; SQLFullCommand += SQLCommand; SQLCommand = "[Client] VARCHAR DEFAULT " + "\"" + "\"" + ")"; SQLFullCommand += SQLCommand; OleDb_Command = new OleDbCommand(SQLFullCommand, OleDb_Connection); OleDb_Command.ExecuteNonQuery(); //выполнение запроса //создание первой записи по умолчению для локального сервера SQLFullCommand = "INSERT INTO ListBase ([Name], [Server], [DataBase], [Uid], [Pwd], [Admin], [Client]) VALUES ('Информационная база №1', 'localhost', 'rapid', 'root', '', 'http://localhost/rapid.com/Admin/', 'http://localhost/rapid.com')"; OleDb_Command = new OleDbCommand(SQLFullCommand, OleDb_Connection); OleDb_Command.ExecuteNonQuery(); //выполнение запроса //отключение соединения OleDb_Connection.Close(); }catch(Exception ex){ MessageBox.Show(ex.ToString()); //Сообщение об ошибке Application.Exit(); } } //-------------------------------------------- //Открытие окна выбора конфигурации ClassForms.Rapid_SelectLoad = new FormSelectLoad(); ClassForms.Rapid_SelectLoad.Show(); //-------------------------------------------- Visible = false; //главная форма становится невидимой }
/// <summary> /// 创建表方法 /// </summary> /// <param name="_TableName">表明</param> /// <param name="_Hashtable">列名和数据类型</param> /// <param name="ADOX.Catalog">主键位置</param> /// <returns>False:创建失败;True创建失败</returns> private bool CreateTable(string _TableName, List <ColumnStruct> _ListColumnStruct, ADOX.Catalog _Catalog) { ADOX.Table _Table = null; try { _Table = new ADOX.Table(); _Table.Name = _TableName; for (int i = 0; i < _ListColumnStruct.Count; i++) { _Table.Columns.Append(_ListColumnStruct[i]._ColumnName, _ListColumnStruct[i]._DataTypeEnum, _ListColumnStruct[i]._ColumnLong); if (_ListColumnStruct[i]._IsKeyPrimary) { _Table.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, _ListColumnStruct[i]._ColumnName, "", ""); } } _Catalog.Tables.Append(_Table); return(true); } catch (Exception ex) { logger.Error(ex.ToString()); } finally { _Table = null; } return(false); }
private void button1_Click(object sender, EventArgs e) { String db_name = "NEWDB.accdb"; String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data" + @" Source=C:\PBloodTestManager\" + db_name; //Create the Database try { ADOX.Catalog cat = new ADOX.Catalog(); cat.Create(connectionString); //Now Close the database ADODB.Connection con = cat.ActiveConnection as ADODB.Connection; if (con != null) con.Close(); MessageBox.Show("Database '" + db_name + "' Created"); } catch (Exception) { MessageBox.Show("Database already exists"); } String tableName = "NEW_TABLE"; String createSQL = "CREATE TABLE " + tableName + "(" + "SNo Integer PRIMARY KEY," + "TestDate Date," + " Glucose Double," + " Cholesterol Double," + " LDL Double," + " HDL Double," + " Triglycerides Double," + " Fibrinogen Double," + " HemoglobinA1C Double," + " DHEA Double," + " PSA Double," + " Homocysteine Double," + " CRP Double," + " TSH Double," + " Testosterone Double," + " Estradiol Double" + ")"; OleDbConnection conn = new OleDbConnection(connectionString); OleDbCommand dbCmd = new OleDbCommand(); try { conn.Open(); //MessageBox.Show(createSQL); dbCmd.Connection = conn; dbCmd.CommandText = createSQL; dbCmd.ExecuteNonQuery(); MessageBox.Show("Table Created"); } catch (OleDbException exp) { MessageBox.Show("Database Error:" + exp.Message.ToString()); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
private bool lFile(DataSet ds) { bool result = false; string strMes = ""; OleDbConnection conn; ADODB.Connection adodbCon = new ADODB.Connection(); adodbCon.ConnectionString = connString; ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table tab; DAO.DBEngine dbEngine = new DAO.DBEngine(); try { //внесение данных txtLog.AppendLine("Внесение данных"); Application.DoEvents(); string postFix = ""; if (rbTypeTo.Checked) { postFix = "rokb"; } DAO.Database db = dbEngine.OpenDatabase(pathToDb); DAO.Recordset rs = db.OpenRecordset($"ZGLV{postFix}"); foreach (DataRow dr in ds.Tables["ZGLV"].Rows) { rs.AddNew(); rs.Fields["H"].Value = "L"; foreach (DataColumn dc in ds.Tables["ZGLV"].Columns) { rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString(); } rs.Update(); } rs.Close(); // //PERS // if (ds.Tables.Contains("PERS")) { txtLog.AppendLine("Таблица PERS"); Application.DoEvents(); System.Threading.Thread.Sleep(10000); pb.Minimum = 0; pb.Maximum = ds.Tables["PERS"].Rows.Count; pb.Value = 0; Application.DoEvents(); rs = db.OpenRecordset($"PERS{postFix}"); int counter = 0; foreach (DataRow drSchet in ds.Tables["PERS"].Rows) { pb.Value = counter++; Application.DoEvents(); rs.AddNew(); rs.Fields["PLAT"].Value = _PLAT; foreach (DataColumn dc in ds.Tables["PERS"].Columns) { rs.Fields[dc.ColumnName].Value = drSchet[dc.ColumnName].ToString(); } rs.Update(); } rs.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); txtLog.AppendLine(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine); dbEngine = null; } cat = null; return(result); }
private bool hFile(DataSet ds) { bool result = false; string strMes = ""; OleDbConnection conn; ADODB.Connection adodbCon = new ADODB.Connection(); adodbCon.ConnectionString = connString; ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table tab; //int SLUCH_ID = 0; DAO.DBEngine dbEngine = new DAO.DBEngine(); try { string postFix = ""; if (rbTypeTo.Checked) { postFix = "rokb"; } txtLog.AppendLine("Внесение данных"); Application.DoEvents(); //внесение данных string _CODE = "", _NSCHET = "", _N_ZAP = "", _IDCASE = "", _USL_TIP = "2"; txtLog.AppendLine("Таблица ZGLV"); Application.DoEvents(); DAO.Database db = dbEngine.OpenDatabase(pathToDb); DAO.Recordset rs = db.OpenRecordset($"ZGLV{postFix}"); foreach (DataRow dr in ds.Tables["ZGLV"].Rows) { rs.AddNew(); rs.Fields["H"].Value = "H"; foreach (DataColumn dc in ds.Tables["ZGLV"].Columns) { rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString(); } rs.Update(); } rs.Close(); // //SCHET // txtLog.AppendLine("Таблица SCHET"); Application.DoEvents(); rs = db.OpenRecordset($"SCHET{postFix}"); DataRow drSchet = ds.Tables["SCHET"].Rows[0]; _CODE = drSchet["CODE"].ToString(); _NSCHET = drSchet["NSCHET"].ToString(); rs.AddNew(); foreach (DataColumn dc in ds.Tables["SCHET"].Columns) { rs.Fields[dc.ColumnName].Value = drSchet[dc.ColumnName].ToString(); } rs.Update(); rs.Close(); // //ZAP // txtLog.AppendLine("Таблица ZAP"); Application.DoEvents(); pb.Minimum = 0; pb.Maximum = ds.Tables["ZAP"].Rows.Count; pb.Value = 0; int counter = 0; rs = db.OpenRecordset($"ZAP{postFix}"); foreach (DataRow dr in ds.Tables["ZAP"].Rows) { pb.Value = counter++; Application.DoEvents(); rs.AddNew(); _N_ZAP = dr["N_ZAP"].ToString(); int ZAP_Id = int.Parse(dr["ZAP_Id"].ToString()); rs.Fields["CODE"].Value = _CODE; rs.Fields["PLAT"].Value = _PLAT; rs.Fields["NSCHET"].Value = _NSCHET; foreach (DataColumn dc in ds.Tables["ZAP"].Columns) { rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString(); } rs.Update(); // //PACIENT // DAO.Recordset rsPacient = db.OpenRecordset($"PACIENT{postFix}"); if (ds.Tables.Contains("PACIENT")) { List <DataRow> pacList = ds.Tables["PACIENT"].AsEnumerable().Where(m => m.Field <Int32>("ZAP_Id") == ZAP_Id).ToList <DataRow>(); foreach (DataRow drPac in pacList) { rsPacient.AddNew(); rsPacient.Fields["N_ZAP"].Value = _N_ZAP; rsPacient.Fields["PLAT"].Value = _PLAT; foreach (DataColumn dc in ds.Tables["PACIENT"].Columns) { rsPacient.Fields[dc.ColumnName].Value = drPac[dc.Ordinal].ToString(); } rsPacient.Update(); } rsPacient.Close(); } // //SLUCH // if (!ds.Tables.Contains("SLUCH")) { continue; } DAO.Recordset rsSLUCH = db.OpenRecordset($"SLUCH{postFix}"); List <DataRow> sluchList = ds.Tables["SLUCH"].AsEnumerable().Where(m => m.Field <Int32>("ZAP_Id") == ZAP_Id).ToList <DataRow>(); foreach (DataRow drSluch in sluchList) { _IDCASE = drSluch[ds.Tables["SLUCH"].Columns["IDCASE"].Ordinal].ToString(); //SLUCH_ID = int.Parse(drSluch["SLUCH_Id"].ToString()); //if (SLUCH_ID == 1098) //{ // int zz = 0; //} int SLUCH_Id = int.Parse(drSluch[ds.Tables["SLUCH"].Columns["SLUCH_Id"].Ordinal].ToString()); rsSLUCH.AddNew(); rsSLUCH.Fields["N_ZAP"].Value = _N_ZAP; rsSLUCH.Fields["PLAT"].Value = _PLAT; foreach (DataColumn dc in ds.Tables["SLUCH"].Columns) { rsSLUCH.Fields[dc.ColumnName].Value = drSluch[dc.Ordinal].ToString(); } rsSLUCH.Update(); // //HMP // if (ds.Tables.Contains("HMP")) { DAO.Recordset rsHMP = db.OpenRecordset($"HMP{postFix}"); List <DataRow> hmpList = ds.Tables["HMP"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>(); if (hmpList != null && hmpList.Count > 0) { foreach (DataRow drHMP in hmpList) { rsHMP.AddNew(); rsHMP.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["HMP"].Columns) { rsHMP.Fields[dc.ColumnName].Value = drHMP[dc.Ordinal].ToString(); } rsHMP.Update(); } } rsHMP.Close(); } // //NAPR_FROM // if (ds.Tables.Contains("NAPR_FROM")) { DAO.Recordset rsNaprFrom = db.OpenRecordset($"NAPR_FROM{postFix}"); List <DataRow> naprFromList = ds.Tables["NAPR_FROM"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>(); if (naprFromList != null && naprFromList.Count > 0) { foreach (DataRow drNaprFrom in naprFromList) { rsNaprFrom.AddNew(); rsNaprFrom.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["NAPR_FROM"].Columns) { rsNaprFrom.Fields[dc.ColumnName].Value = drNaprFrom[dc.Ordinal].ToString(); } rsNaprFrom.Update(); } } rsNaprFrom.Close(); } // //CONS // if (ds.Tables.Contains("CONS")) { DAO.Recordset rsCons = db.OpenRecordset($"CONS{postFix}"); List <DataRow> consList = ds.Tables["CONS"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>(); if (consList != null && consList.Count > 0) { foreach (DataRow drCons in consList) { rsCons.AddNew(); rsCons.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["CONS"].Columns) { rsCons.Fields[dc.ColumnName].Value = drCons[dc.Ordinal].ToString(); } rsCons.Update(); } } rsCons.Close(); } // //ONK_SL // if (ds.Tables.Contains("ONK_SL")) { DAO.Recordset rsOnkSl = db.OpenRecordset($"ONK_SL{postFix}"); List <DataRow> onkSlList = ds.Tables["ONK_SL"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>(); if (onkSlList != null && onkSlList.Count > 0) { foreach (DataRow drOnkSl in onkSlList) { int OnkSl_Id = int.Parse(drOnkSl[ds.Tables["ONK_SL"].Columns["ONK_SL_Id"].Ordinal].ToString()); rsOnkSl.AddNew(); rsOnkSl.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["ONK_SL"].Columns) { rsOnkSl.Fields[dc.ColumnName].Value = drOnkSl[dc.Ordinal].ToString(); } rsOnkSl.Update(); // //B_DIAG // if (ds.Tables.Contains("B_DIAG")) { DAO.Recordset rsBDiag = db.OpenRecordset($"B_DIAG{postFix}"); List <DataRow> bDiagList = ds.Tables["B_DIAG"].AsEnumerable().Where(m => m.Field <Int32>("ONK_SL_Id") == OnkSl_Id).ToList <DataRow>(); if (bDiagList != null && bDiagList.Count > 0) { foreach (DataRow drBDiag in bDiagList) { rsBDiag.AddNew(); rsBDiag.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["B_DIAG"].Columns) { rsBDiag.Fields[dc.ColumnName].Value = drBDiag[dc.Ordinal].ToString(); } rsBDiag.Update(); } } rsBDiag.Close(); } // //ONK_USL // if (ds.Tables.Contains("ONK_USL")) { DAO.Recordset rsOnkUsl = db.OpenRecordset($"ONK_USL{postFix}"); List <DataRow> onkUslList = ds.Tables["ONK_USL"].AsEnumerable().Where(m => m.Field <Int32>("ONK_SL_Id") == OnkSl_Id).ToList <DataRow>(); if (onkUslList != null && onkUslList.Count > 0) { foreach (DataRow drOnkUsl in onkUslList) { rsOnkUsl.AddNew(); rsOnkUsl.Fields["IDCASE"].Value = _IDCASE; int ONK_USL_Id = int.Parse(drOnkUsl["ONK_USL_Id"].ToString()); foreach (DataColumn dc in ds.Tables["ONK_USL"].Columns) { rsOnkUsl.Fields[dc.ColumnName].Value = drOnkUsl[dc.Ordinal].ToString(); } rsOnkUsl.Update(); // //LEK_PR // if (ds.Tables.Contains("LEK_PR")) { DAO.Recordset rsLekPr = db.OpenRecordset($"LEK_PR{postFix}"); List <DataRow> lekPrList = ds.Tables["LEK_PR"].AsEnumerable().Where(m => m.Field <Int32>("ONK_USL_Id") == ONK_USL_Id).ToList <DataRow>(); if (lekPrList != null && lekPrList.Count > 0) { foreach (DataRow drLekPr in lekPrList) { int LEK_PR_Id = int.Parse(drLekPr["LEK_PR_Id"].ToString()); List <DataRow> dateInjList = ds.Tables["DATE_INJ"].AsEnumerable().Where(m => m.Field <Int32>("LEK_PR_Id") == LEK_PR_Id).ToList <DataRow>(); if (dateInjList != null && dateInjList.Count > 0) { foreach (DataRow drDateInj in dateInjList) { rsLekPr.AddNew(); foreach (DataColumn dc in ds.Tables["LEK_PR"].Columns) { rsLekPr.Fields[dc.ColumnName].Value = drLekPr[dc.Ordinal].ToString(); } rsLekPr.Fields["IDCASE"].Value = _IDCASE; rsLekPr.Fields["USL_TIP"].Value = "2"; rsLekPr.Fields["DATE_INJ"].Value = drDateInj["DATE_INJ_Text"].ToString(); rsLekPr.Update(); } } else { rsLekPr.AddNew(); rsLekPr.Fields["IDCASE"].Value = _IDCASE; rsLekPr.Fields["USL_TIP"].Value = "2"; rsLekPr.Update(); } } } rsLekPr.Close(); } } } rsOnkUsl.Close(); } } } rsOnkSl.Close(); } // //USL // if (ds.Tables.Contains("USL")) { DAO.Recordset rsUSL = db.OpenRecordset($"USL{postFix}"); List <DataRow> uslList = ds.Tables["USL"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>(); if (uslList != null && uslList.Count > 0) { foreach (DataRow drUSL in uslList) { int USL_Id = int.Parse(drUSL["USL_Id"].ToString()); rsUSL.AddNew(); rsUSL.Fields["IDCASE"].Value = _IDCASE; rsUSL.Fields["N_ZAP"].Value = _N_ZAP; rsUSL.Fields["PLAT"].Value = _PLAT; foreach (DataColumn dc in ds.Tables["USL"].Columns) { rsUSL.Fields[dc.ColumnName].Value = drUSL[dc.Ordinal].ToString(); } rsUSL.Update(); // //SL_KOEF // if (ds.Tables.Contains("SL_KOEF")) { DAO.Recordset rsSlKoef = db.OpenRecordset($"SL_KOEF{postFix}"); List <DataRow> slKoefList = ds.Tables["SL_KOEF"].AsEnumerable().Where(m => m.Field <Int32>("USL_Id") == USL_Id).ToList <DataRow>(); if (slKoefList != null && slKoefList.Count > 0) { foreach (DataRow drSlKoef in slKoefList) { rsSlKoef.AddNew(); rsSlKoef.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["SL_KOEF"].Columns) { rsSlKoef.Fields[dc.ColumnName].Value = drSlKoef[dc.Ordinal].ToString(); } rsSlKoef.Update(); } } rsSlKoef.Close(); } // //SL_KOEF // if (ds.Tables.Contains("KSG_KPG")) { DAO.Recordset rsKSGKPG = db.OpenRecordset($"KSG_KPG{postFix}"); List <DataRow> KSGKPG = ds.Tables["KSG_KPG"].AsEnumerable().Where(m => m.Field <Int32>("USL_Id") == USL_Id).ToList <DataRow>(); if (KSGKPG != null && KSGKPG.Count > 0) { foreach (DataRow drKSGKPG in KSGKPG) { rsKSGKPG.AddNew(); rsKSGKPG.Fields["IDCASE"].Value = _IDCASE; foreach (DataColumn dc in ds.Tables["KSG_KPG"].Columns) { rsKSGKPG.Fields[dc.ColumnName].Value = drKSGKPG[dc.Ordinal].ToString(); } rsKSGKPG.Update(); } } rsKSGKPG.Close(); } } } rsUSL.Close(); } } rsSLUCH.Close(); } rs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); txtLog.AppendLine(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine); dbEngine = null; } cat = null; return(result); }
private bool createSchema() { bool result = false; string strMsg = ""; OleDbConnection conn; ADODB.Connection adodbCon = new ADODB.Connection(); adodbCon.ConnectionString = connString; ADOX.Catalog cat = new ADOX.Catalog(); ADOX.Table tab; try { DirectoryInfo dir = new DirectoryInfo($@"{Path.GetDirectoryName(txtPathToArc.Text)}\unarc"); FileInfo[] filesH = dir.GetFiles("H*.xml"); if (filesH.Length == 0) { strMsg = "Файлы для обработки отсутствуют"; MessageBox.Show(strMsg); txtLog.AppendLine(strMsg); return(result); } foreach (FileInfo fi in filesH) { DataSet ds = new DataSet(); ds.ReadXmlSchema(fi.FullName); foreach (string tableName in tableListH) { if (ds.Tables.Contains(tableName)) { DataTable dt = ds.Tables[tableName]; foreach (DataColumn dc in dt.Columns) { if (!addFieldsH[tableName].Contains(dc.ColumnName)) { addFieldsH[tableName].Add(dc.ColumnName); } } } } } adodbCon.Open(); cat.ActiveConnection = adodbCon; conn = new OleDbConnection(connString); if (conn.State == ConnectionState.Closed) { conn.Open(); } txtLog.AppendLine("Создание структуры БД"); Application.DoEvents(); string postFix = ""; if (rbTypeTo.Checked) { postFix = "rokb"; } foreach (string tabName in tableListH) { tab = new ADOX.Table(); tab.Name = $"{tabName}{postFix}"; //id ADOX.Column column = new ADOX.Column(); column.Name = "id"; column.Type = ADOX.DataTypeEnum.adInteger; column.ParentCatalog = cat; column.Properties["AutoIncrement"].Value = true; tab.Columns.Append(column); foreach (string str in addFieldsH[tabName]) { tab.Columns.Append(defCol(str)); } cat.Tables.Append(tab); } //L FileInfo[] filesL = dir.GetFiles("L*.xml"); if (filesL.Length == 0) { strMsg = "Файлы для обработки отсутствуют"; MessageBox.Show(strMsg); txtLog.AppendLine(strMsg); return(result); } foreach (FileInfo fi in filesL) { DataSet ds = new DataSet(); ds.ReadXmlSchema(fi.FullName); foreach (string tableName in tableListL) { if (ds.Tables.Contains(tableName)) { DataTable dt = ds.Tables[tableName]; foreach (DataColumn dc in dt.Columns) { if (!addFieldsL[tableName].Contains(dc.ColumnName)) { addFieldsL[tableName].Add(dc.ColumnName); } } } } } foreach (string tabName in tableListL) { tab = new ADOX.Table(); tab.Name = $"{tabName}{postFix}"; //id ADOX.Column column = new ADOX.Column(); column.Name = "id"; column.Type = ADOX.DataTypeEnum.adInteger; column.ParentCatalog = cat; column.Properties["AutoIncrement"].Value = true; tab.Columns.Append(column); foreach (string str in addFieldsL[tabName]) { tab.Columns.Append(defCol(str)); } cat.Tables.Append(tab); } if (conn.State == ConnectionState.Open) { conn.Close(); } strMsg = "Структура БД создана"; txtLog.AppendLine(strMsg); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
private void _InitSqlLst() { // if (queryLst != null) return; if (con == null) throw new InvalidOperationException(); var querylst = new List<string>(); string s; var cat = new ADOX.Catalog(); var cmd = new ADODB.Command(); queryLst = new List<Query>(); //アクションクエリ var rs = con.OpenSchema(ADODB.SchemaEnum.adSchemaProcedures); while (!rs.EOF) { s = rs.Fields["PROCEDURE_NAME"].Value.ToString(); rs.MoveNext(); if (!s.StartsWith("~")) querylst.Add(s); } cat.ActiveConnection = con; foreach (var q in querylst) { // cmd = (ADODB.Command)cat.Procedures[q].Command; var sql = cmd.CommandText.ToUpper(); //var name = cmd.Name; var name = q; if (!(sql.StartsWith("UPDATE") || sql.StartsWith("INSERT"))) return; var query = new Query(name, sql); queryLst.Add(query); //if (sql.StartsWith("UPDATE")) // updateSqlLst.Add(sql); //if (sql.StartsWith("INSERT")) // insertSqlLst.Add(sql); } }