コード例 #1
2
        public object[] db_access(string strSQL)
        {
            ADODB.Connection objCon;
            ADODB.Recordset objRec;
            object[,] dataRows;
            object[] dataSuite;
            string strCon;

            objCon = new ADODB.Connection();
            objRec = new ADODB.Recordset();

            //establish the connection string and open the database connection
            strCon = "driver={MySQL ODBC 5.1 Driver};server=107.22.232.228;uid=qa_people;pwd=thehandcontrols;" +
                "database=functional_test_data;option=3";

            objCon.Open(strCon);

            //execute the SQL and return the recrodset of results
            objRec = objCon.Execute(strSQL, out missing, 0);

            //populate a two dinmensional object array with the results
            dataRows = objRec.GetRows();

            //get a one dimensional array that can be placed into the Test Suite dropdown
            dataSuite = thinArray(dataRows);

            //close the recordset
            objRec.Close();

            //close the database connection
            objCon.Close();

            return dataSuite;
        }
コード例 #2
2
ファイル: ResultColumns.cs プロジェクト: attila3453/alsing
		override internal void LoadAll()
		{
			ADODB.Connection cnn = new ADODB.Connection();
			ADODB.Recordset rs = new ADODB.Recordset();
			ADOX.Catalog cat = new ADOX.Catalog();
    
			// Open the Connection
			cnn.Open(dbRoot.ConnectionString, null, null, 0);
			cat.ActiveConnection = cnn;

			ADOX.Procedure proc = cat.Procedures[this.Procedure.Name];
       
			// Retrieve Parameter information
			rs.Source = proc.Command as ADODB.Command;
			rs.Fields.Refresh();

			Pervasive.PervasiveResultColumn resultColumn;

			if(rs.Fields.Count > 0)
			{
				int ordinal = 0;
			
				foreach(ADODB.Field field in rs.Fields)
				{
					resultColumn = this.dbRoot.ClassFactory.CreateResultColumn() as Pervasive.PervasiveResultColumn;
					resultColumn.dbRoot = this.dbRoot;
					resultColumn.ResultColumns = this;

					resultColumn.name = field.Name;
					resultColumn.ordinal = ordinal++;
					resultColumn.typeName = field.Type.ToString();

					this._array.Add(resultColumn);
				}
			}

			cnn.Close();
		}
コード例 #3
0
        public static void ReadDB(string tableName, string fileName)
        {
            string filePath = @"D:\xl2cad.mdb";

            if (File.Exists(filePath))
            {
                //select * into 建立 新的表。
                //[[Excel 8.0;database= excel名].[sheet名] 如果是新建sheet表不能加$,如果向sheet里插入数据要加$. 
                //sheet最多存储65535条数据。
                ADODB.Connection cn = null;
                try
                {
                    object ra  = null;
                    string sql = "select top 65535 * into [Excel 8.0;database=" + fileName + "].[" + tableName + "] from " + tableName;
                    cn = new ADODB.Connection();
                    cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath, null, null, -1);
                    cn.Execute(sql, out ra, -1);
                    cn.Close();
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cn);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    cn.Close();
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cn);
                    System.GC.Collect();
                }
            }
        }
コード例 #4
0
        public static DataTable LoadDBF(string FilePath, string Sql)
        {
            ADODB.Recordset  rs   = new ADODB.Recordset();
            ADODB.Connection conn = new ADODB.Connection();
            try
            {
                conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='dbase 5.0';Data Source = " + System.IO.Path.GetDirectoryName(FilePath));


                rs.Open(Sql, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly);
                object ary = rs.GetRows();
                object[,] aa = (object[, ])ary;

                int UB1 = aa.GetUpperBound(1);
                int UB0 = aa.GetUpperBound(0);


                DataTable dt = new DataTable();

                for (int i = 0; i <= UB0; i++)
                {
                    dt.Columns.Add(i.ToString());
                }



                for (int i = 0; i <= UB1; i++)
                {
                    DataRow dr = dt.NewRow();

                    for (int j = 0; j <= UB0; j++)
                    {
                        dr[j] = aa[j, i].ToString();
                    }

                    dt.Rows.Add(dr);
                }

                rs.Close();
                conn.Close();


                return(dt);
            }
            catch (Exception e)
            {
                rs.Close();
                conn.Close();
                return(null);
            }
        }
コード例 #5
0
        public static object[,] LoadExcelAry(string FilePath, string Sql)
        {
            ADODB.Connection conn = new ADODB.Connection();
            ADODB.Recordset  rs   = new ADODB.Recordset();

            try
            {
                //FilePath = "C:\\Users\\Administrator\\Desktop\\测试模版\\Shp\\1\\凤凰观村2组.xls";
                //Sql = "Select 宗地编码,土地类型,承包方名称,承包方编码 From [地块信息$] Order By 承包方编码,宗地编码";

                //Select 宗地编码,土地类型,承包方名称,承包方编码 From [地块信息$] Order By 承包方编码,宗地编码
                //Select * From [发包方信息$A1:BB2000]
                conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + FilePath);
                rs.Open(Sql, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly, -1);
                object ary = rs.GetRows();
                object[,] aa = (object[, ])ary;

                rs.Close();
                conn.Close();



                int UB1 = aa.GetUpperBound(1);
                int UB0 = aa.GetUpperBound(0);

                for (int i = 0; i <= UB1; i++)
                {
                    for (int j = 0; j <= UB0; j++)
                    {
                        ErrorMsg = (i + "-" + j);
                        if (Convert.IsDBNull(aa[j, i]) || aa[j, i] == null)
                        {
                            aa[j, i] = "";
                        }
                    }
                }


                //object test0 = aa[1, 3];
                //object test1 = aa[15, 3];
                //object test2 = aa[17, 3];
                return(aa);
            }
            catch (Exception)
            {
                rs.Close();
                conn.Close();
                return(null);
            }
        }
コード例 #6
0
        /// <summary>
        /// This function will create the database that will be used for retreiving the PRPO data.
        /// </summary>
        /// <exception cref="DatabaseCreationFailureException"></exception>
        /// <returns>
        /// A boolean value indicating whether or not he database was created.
        /// </returns>
        public static bool CreateAccessDB()
        {
            bool result = false;

            ADOX.Catalog cat = new ADOX.Catalog();

            if (!File.Exists(AI.Path))
            {
                try
                {
                    cat.Create(AI.connectionString());
                    ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
                    if (con != null)
                    {
                        con.Close();
                    }
                    result = true;
                    AccessDatabaseUtils.US_PRPO_TableExists = false;
                    AccessDatabaseUtils.MX_PRPO_TableExists = false;
                }
                catch (Exception)
                {
                    throw new DatabaseCreationFailureException("There was an error while creating the MS Access Database.");
                }
            }
            return(result);
        }
コード例 #7
0
        public object[] db_access(string strSQL)
        {
            ADODB.Connection objCon;
            ADODB.Recordset  objRec;
            object[,] dataRows;
            object[] dataSuite;
            string   strCon;

            objCon = new ADODB.Connection();
            objRec = new ADODB.Recordset();

            //establish the connection string and open the database connection
            strCon = "driver={MySQL ODBC 5.1 Driver};server=107.22.232.228;uid=qa_people;pwd=thehandcontrols;" +
                     "database=functional_test_data;option=3";

            objCon.Open(strCon);

            //execute the SQL and return the recrodset of results
            objRec = objCon.Execute(strSQL, out missing, 0);

            //populate a two dinmensional object array with the results
            dataRows = objRec.GetRows();

            //get a one dimensional array that can be placed into the Test Suite dropdown
            dataSuite = thinArray(dataRows);

            //close the recordset
            objRec.Close();

            //close the database connection
            objCon.Close();

            return(dataSuite);
        }
コード例 #8
0
        public bool Execute(string sql)
        {
            bool   stat = false;
            object obj;

            try
            {
                if (Connected() == true)
                {
                    if (cnn == null)
                    {
                        cnn = new ADODB.Connection();
                    }
                    if (cnn.State == 0)
                    {
                        cnn.Open(cnn_str, "", "", 0);
                    }
                    if (cnn.State == 1)
                    {
                        cnn.Execute(sql, out obj, 0);
                        cnn.Close();
                        stat = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(stat);
        }
コード例 #9
0
 /// <summary>
 /// 在access数据库中创建表
 /// </summary>
 /// <param name="filePath">数据库表文件全路径如D:\\NewDb.mdb 没有则创建 </param>
 /// <param name="tableName">表名</param>
 /// <param name="colums">ADOX.Column对象数组</param>
 public static bool CreateAccessTable(string filePath, string tableName, params ADOX.Column[] colums)
 {
     ADOX.Catalog catalog = new Catalog();
     //数据库文件不存在则创建
     if (!File.Exists(filePath))
     {
         try
         {
             catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Jet OLEDB:Engine Type=5");
         }
         catch (System.Exception ex)
         {
             return(false);
         }
     }
     ADODB.Connection cn = new ADODB.Connection();
     cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath, null, null, -1);
     catalog.ActiveConnection = cn;
     ADOX.Table table = new ADOX.Table();
     table.Name = tableName;
     foreach (var column in colums)
     {
         table.Columns.Append(column);
     }
     colums[0].ParentCatalog = catalog;
     colums[0].Properties["AutoIncrement"].Value = true;                                         //设置自动增长
     table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, colums[0], null, null); //定义主键
     catalog.Tables.Append(table);
     cn.Close();
     return(true);
 }
コード例 #10
0
        public static string ReadExcel(string FilePath, int C, int R)
        {
            ADODB.Connection conn = new ADODB.Connection();
            ADODB.Recordset  rs   = new ADODB.Recordset();

            string Sql = "Select * From [Sheet1$]";

            //Select 宗地编码,土地类型,承包方名称,承包方编码 From [地块信息$] Order By 承包方编码,宗地编码
            conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + FilePath);
            rs.Open(Sql, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly, -1);
            object ary = rs.GetRows();

            object[,] aa = (object[, ])ary;

            rs.Close();
            conn.Close();



            if ((string)aa[C - 1, R - 2] == null)
            {
                return("");
            }


            return((string)aa[C - 1, R - 2]);
        }
コード例 #11
0
        /// <summary>
        /// Création de la base de données Acces
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool 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 = "Table1";
            table.Columns.Append("Field1");
            table.Columns.Append("Field2");
            try
            {
                cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + this.dataBaseName + ".accdb; 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 ex)
            {
                result = false;
            }
            cat = null;
            return(result);
        }
コード例 #12
0
ファイル: Class1.cs プロジェクト: quipmed/WindowsFormsApp3
 public static void CerrarBD()
 {
     if (Convert.ToInt32(cnn.State) == 1)
     {
         cnn.Close();
     }
 }
コード例 #13
0
        /// <summary>
        /// Upgrades a Version 1.0 database to Version 1.1.  This upgrade is the
        /// addition of the field "TerminalParameters" to the table tblFunctionSet.
        /// </summary>
        /// <returns></returns>
        private static bool UpgradeDatabase()
        {
            try
            {
                ADODB.Connection con = new ADODB.Connection();
                con.Open(ConnectionString, "", "", 0);

                Catalog dbCatalog = new Catalog();
                dbCatalog.ActiveConnection = con;

                Table dbTable = dbCatalog.Tables["tblFunctionSet"];

                dbTable.Columns.Append("TerminalParameters", ADOX.DataTypeEnum.adBoolean, 1);
                dbTable.Columns[dbTable.Columns.Count - 1].Properties["Default"].Value = "False";

                con.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to correctly upgrade the database");
                return(false);
            }

            //
            // If the upgrade succeeded, update the version value in the admin table
            return(UpdateField(1, "tblAdministration", "Description", GPEnums.DATABASE_VERSION));
        }
コード例 #14
0
        public static void CreateFile(string fileName, string pwd = "")
        {
            string dir = Path.GetDirectoryName(fileName);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (!File.Exists(fileName))
            {
                ADOX.Catalog cat = new ADOX.Catalog();
                cat.Create(Provider + @"Data Source=" + fileName + ";" + Password + "=" + pwd);

                ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
                if (con != null)
                {
                    con.Close();
                }
                cat.ActiveConnection = null;

                Marshal.ReleaseComObject(cat);
                cat = null;

                GC.Collect();
            }
        }
コード例 #15
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //创建数据库文件
            ADOX.Catalog catalog = new Catalog();
            catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb;Jet OLEDB:Engine Type=5");
            Debug.WriteLine("DataBase created");

            //建表
            ADODB.Connection cn = new ADODB.Connection();
            cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb", null, null, -1);
            catalog.ActiveConnection = cn;

            ADOX.Table table = new ADOX.Table();
            table.Name = "FirstTable";

            ADOX.Column column = new ADOX.Column();
            column.ParentCatalog = catalog;
            column.Name = "RecordId";
            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("CustomerName", DataTypeEnum.adVarWChar, 50);
            table.Columns.Append("Age", DataTypeEnum.adInteger, 9);
            table.Columns.Append("Birthday", DataTypeEnum.adDate, 0);
            catalog.Tables.Append(table);

            cn.Close();
        }
コード例 #16
0
        public static void closeConnection()
        {
            // ERROR: Not supported in C#: OnErrorStatement

            cnnDB.Close();
            cnnDB = null;
        }
コード例 #17
0
        /// <summary>
        /// 删除表
        /// </summary>
        /// <param name="strConnection"></param>
        /// <param name="strTableName"></param>
        public static void DeleteDBTable(string strConnection, string strTableName)
        {
            ADOX.Catalog     catalog = new Catalog();
            ADODB.Connection cn      = new ADODB.Connection();

            try
            {
                OleDbConnection conn = new OleDbConnection(strConnection);
                conn.Open();
                cn.Open(strConnection, null, null, -1);
                catalog.ActiveConnection = cn;

                bool flag = dbutils.GetTables(conn, strTableName);
                if (flag)//判断表名是否存在
                {
                    catalog.Tables.Delete(strTableName);
                }

                //此处一定要关闭连接,否则添加数据时候会出错
                catalog = null;
                Application.DoEvents();
                cn.Close();
            }
            catch (Exception ex)
            {
                loghelp.log.Fatal(ex.Message, ex);
            }
        }
コード例 #18
0
        //创建数据表
        public bool CreateAccessTable(string FilePath, string tableName, params ADOX.Column[] colums)
        {
            bool bolReturn = false;

            ADOX.Catalog clg = new Catalog();
            //数据库文件存在
            try {
                if (CreateAccess(FilePath) == true)
                {
                    ADODB.Connection cn = new ADODB.Connection(); //连接已创建的数据库文件
                    cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath, null, null, -1);
                    clg.ActiveConnection = cn;                    //打开已创建的数据库文件

                    ADOX.Table table1 = new ADOX.Table();
                    table1.Name = tableName;
                    foreach (var column in colums)
                    {
                        if (column.Name != null)
                        {
                            table1.Columns.Append(column);
                        }
                    }
                    clg.Tables.Append(table1);
                    cn.Close();
                    bolReturn = true;
                }
            }catch (Exception ex) {
                MessageBox.Show("创建失败\r\n" + ex.ToString(), "提示");
            }
            return(bolReturn);
        }
コード例 #19
0
        /// <summary>
        /// Extracts the data contained in the ADO recordset and stores it in
        /// XmlSource.  If there is another recordset, then the first was actually
        /// Extended attributes metadata, so that document is move to XmlExtendedAttributes,
        /// and the data in the second recordset is store into XmlSource.
        /// </summary>
        private void GetSource()
        {
            ADODB.Connection oConn = null;
            if (oRs == null)
            {
                OpenRecordset(CreateCommand(ref oConn));
            }
            MSXML2.DOMDocument D1 = new MSXML2.DOMDocumentClass();
            // load the 1st dataset
            oRs.Save(D1, ADODB.PersistFormatEnum.adPersistXML);
            XmlSource = new XmlDocument();
            XmlSource.LoadXml(D1.xml);

            object RecordsAffected;

            oRs = oRs.NextRecordset(out RecordsAffected);
            if (oRs != null && oRs.State == 1)
            {
                XmlExtendedAttributes = XmlSource;
                // Load the 2nd dataset
                oRs.Save(D1, ADODB.PersistFormatEnum.adPersistXML);
                XmlSource = new XmlDocument();
                XmlSource.LoadXml(D1.xml);
            }
            if (oRs != null && oRs.State == 1)
            {
                oRs.Close();
            }
            if (oConn != null)
            {
                oConn.Close();
            }
        }
コード例 #20
0
        //修改数据库密码
        public void editDBPwd_B(string old_password, string new_password)
        {
            try
            {
                string fileName = Application.StartupPath + @"\source\StuContact.mdb";//数据库路径
                string conn     = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Jet OLEDB:Database password="******"ALTER DATABASE PASSWORD " + new_password + " " + old_password;

                ADODB.Connection cn = new ADODB.Connection();
                cn.Mode = ADODB.ConnectModeEnum.adModeShareExclusive;//以独占模式打开数据库,不然不能修改密码
                cn.Open(conn, null, null, -1);
                // 执行 SQL 语句以更改密码
                object num;
                cn.Execute(sql, out num, -1);
                cn.Close();

                //开始修改配置文件
                config.writeConfig_IsEditDBandAddPwd(true, new_password);
                MessageBox.Show("密码修改成功,请牢记您的密码", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据库密码未修改,因为:" + ex.Message, "提示", MessageBoxButtons.OK);
            }
        }
コード例 #21
0
        private void menge_Produkt3_Button_Click(object sender, EventArgs e)
        {
            metroGrid3.Rows.Clear();
            //Recordset
            ADODB.Connection cn = new ADODB.Connection();
            ADODB.Recordset  rs = new ADODB.Recordset();
            try
            {
                cn.Open(cnStr);
                rs.Open("Select Artikel, Sum(Anzahl) as Anzahl_Menge From Listen where Endprodukt = 3 group by Artikel", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);

                int i = 0;

                while (!rs.EOF)
                {
                    metroGrid3.Rows.Add();
                    metroGrid3.Rows[i].Cells["Artikel_Mengen"].Value = Convert.ToInt32(rs.Fields["Artikel"].Value);
                    metroGrid3.Rows[i].Cells["Anzahl_Menge"].Value   = Convert.ToInt32(rs.Fields["Anzahl_Menge"].Value);
                    rs.MoveNext();
                    i++;
                }
                rs.Close();
            }
            catch (Exception fehler)
            {
                Console.WriteLine("Ein Fehler ist aufgetreten", fehler);              //Try catch überprüfen....
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #22
0
        public override IList <Column> GetTableColumns(IDbConnection connection, string schemaName, string tableName, string databaseInstanceName = null)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }

            var columns = new List <Column>();
            var cnn     = new ADODB.Connection();

            try
            {
                cnn.Open(connection.ConnectionString);
                var catalog = new Catalog();
                catalog.ActiveConnection = cnn;

                foreach (ADOX.Table table in catalog.Tables)
                {
                    if (_systemTablesList.Any(
                            x => string.Equals(table.Name, x, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    if (!string.Equals(table.Name, tableName))
                    {
                        continue;
                    }

                    var tab = new Table(table.Name, MsAccess2003DatabaseServer.DefaultSchema);
                    foreach (ADOX.Column column in table.Columns)
                    {
                        var col = GetColumn(column, tab);
                        columns.Add(col);
                    }
                    return(columns);
                }
            }
            finally
            {
                try
                {
                    cnn.Close();
                }
                catch
                {
                }
            }
            return(columns);

            //_log.DebugFormat("Getting column for schema {0} and table {1} ...", schemaName, tableName);
            //var t = new Table(tableName, _defaultSchema);
            //var columns = GetTableColumnsDefault<OleDbType>(connection, t);
            //_log.DebugFormat("Retrieved {0}  column(s).", columns.Count.ToString("#,0"));
            //return columns.OrderBy(x => x.Name).ToList();
        }
コード例 #23
0
        //在指定的Access数据库中创建配置的表格
        public static bool CreateConfTable()
        {
            Catalog catalog = new Catalog();

            ADODB.Connection cn = new ADODB.Connection();
            try {
                cn.Open(DBLink);
                catalog.ActiveConnection = cn;
                Table table = new Table();
                table.ParentCatalog = catalog;
                table.Name          = CONF_TABLE;
                //字段
                Column col = new Column();
                col.ParentCatalog = catalog;
                col.Name          = "id";
                table.Columns.Append(col, DataTypeEnum.adVarWChar, 50); //默认数据类型和字段大小
                table.Keys.Append("pk_id", KeyTypeEnum.adKeyPrimary, col, null, null);
                Column col2 = new Column();
                col2.ParentCatalog = catalog;
                col2.Name          = "bgtime";
                col2.Attributes    = ColumnAttributesEnum.adColNullable; //允许空值
                table.Columns.Append(col2, DataTypeEnum.adDBTime);       //默认数据类型和字段大小
                catalog.Tables.Append(table);
                cn.Close();
                logger.Info("完成创建" + CONF_TABLE + "表");
            }
            catch (System.Exception ex)
            {
                //Trace.TraceWarning("Access连接打开失败", ex);
                logger.Error(ex, "创建" + CONF_TABLE + "表失败");
                return(false);
            }

            return(true);
        }
コード例 #24
0
        private void cmdPrint_Click(System.Object eventSender, System.EventArgs eventArgs)
        {
            short  x         = 0;
            string strDBPath = null;

            Scripting.FileSystemObject fso = new Scripting.FileSystemObject();

            if (!string.IsNullOrEmpty(DataList1.BoundText))
            {
                strDBPath = modRecordSet.serverPath + "month" + gMonth - this.cmbMonth.SelectedIndex + ".mdb";
                if (fso.FileExists(strDBPath))
                {
                    var _with1 = cnnDBStatement;
                    _with1.Provider = "MSDataShape";
                    cnnDBStatement.Open("Data Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strDBPath + ";User Id=liquid;Password=lqd;Jet OLEDB:System Database=" + modRecordSet.serverPath + "Secured.mdw");

                    SupplierStatement(ref Convert.ToInt32(DataList1.BoundText));

                    cnnDBStatement.Close();
                }
                else
                {
                    Interaction.MsgBox("There is no previous month statement for this Supplier", MsgBoxStyle.ApplicationModal + MsgBoxStyle.OkOnly + MsgBoxStyle.Information, _4PosBackOffice.NET.My.MyProject.Application.Info.Title);
                    this.Close();
                }
            }
        }
コード例 #25
0
ファイル: frmMain.cs プロジェクト: mioux/lecteur-access
        /// <summary>
        /// Fermeture d'une connexion sur un catalogue ADOX
        /// </summary>
        /// <param name="cat"></param>

        private void CloseCatalogConnection(Catalog cat)
        {
            ADODB.Connection con = (ADODB.Connection)cat.ActiveConnection;
            if (con != null)
            {
                con.Close();
            }
        }
コード例 #26
0
        public override IList <View> GetViews(IDbConnection connection, string schemaName, string databaseInstanceName = null)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            var cnn = new ADODB.Connection();

            try
            {
                var views = new List <View>();
                cnn.Open(connection.ConnectionString);
                var catalog = new Catalog();
                catalog.ActiveConnection = cnn;

                foreach (ADOX.View view in catalog.Views)
                {
                    if (_systemViewsList.Any(
                            x => string.Equals(view.Name, x, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }
                    views.Add(new View(view.Name, MsAccess2003DatabaseServer.DefaultSchema));
                }
                return(views);
            }
            finally
            {
                try
                {
                    cnn.Close();
                }
                catch
                {
                }
            }


            //if (connection == null) throw new ArgumentNullException("connection");
            //var conn = connection as OleDbConnection;
            //if (conn == null)
            //{
            //    throw new Exception("Microsoft Access database requires OleDbConnection");
            //}
            //var views = new List<View>();
            //DataTable queries = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Views, null);
            //if (queries != null)
            //{
            //    foreach (DataRow row in queries.Rows)
            //    {
            //        var viewName = row["TABLE_NAME"].ToString();
            //        //var viewSql = row["VIEW_DEFINITION"].ToString();
            //        var view = new View(viewName, _defaultSchema);
            //        views.Add(view);
            //    }
            //}
            //return views.OrderBy(x => x.Name).ToList();
        }
コード例 #27
0
        public override IList <Table> GetTables(IDbConnection connection, string schemaName, string databaseInstanceName = null)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            var cnn = new ADODB.Connection();

            try
            {
                var tables = new List <Table>();
                cnn.Open(connection.ConnectionString);
                var catalog = new Catalog();
                catalog.ActiveConnection = cnn;

                var viewNames = (catalog.Views.Cast <ADOX.View>().Select(view => view.Name)).ToList();

                foreach (ADOX.Table table in catalog.Tables)
                {
                    if (_systemTablesList.Any(
                            x => string.Equals(table.Name, x, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    if (viewNames.Any(
                            x => string.Equals(table.Name, x, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    tables.Add(new Table(table.Name, MsAccess2003DatabaseServer.DefaultSchema));
                }
                return(tables);
            }
            finally
            {
                try
                {
                    cnn.Close();
                }
                catch
                {
                }
            }

            //var tblrestrictions = new[] {null, null, null, "TABLE"};
            //var tables = new List<Table>();
            //var olecon = (OleDbConnection) connection;
            //var dataTable = olecon.GetSchema("tables", tblrestrictions);
            //foreach (DataRow dataRow in dataTable.Rows)
            //{
            //    var tableName = (string) dataRow["TABLE_NAME"];
            //    tables.Add(new Table(tableName, MsAccess2003DatabaseServer.DefaultSchema));
            //}
            //_log.DebugFormat("Retrieved {0}  table(s).", tables.Count.ToString("#,0"));
            //return tables.OrderBy(x => x.Name).ToList();
        }
コード例 #28
0
 private void Cleanup()
 {
     if (_connection != null && _connection.State == (int)ADODB.ObjectStateEnum.adStateOpen)
     {
         _connection.Close();
     }
     _connection = null;
     _catalog    = null;
 }
コード例 #29
0
ファイル: AccessHelper.cs プロジェクト: icprog/CANNetwork
        /// <summary>
        /// 新建mdb表,mdbHead是一个ArrayList,存储的是table表中的具体列名
        /// </summary>
        /// <param name="mdbPath"></param>
        /// <param name="tableName"></param>
        /// <param name="mdbHead"></param>
        /// <returns></returns>
        private static bool CreateMDBTable(string tableName, ArrayList mdbHead)
        {
            //ADODB需添加com程序集
            try
            {
                ADOX.CatalogClass cat = new ADOX.CatalogClass();
                string            sAccessConnection
                    = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbpath;
                ADODB.Connection cn = new ADODB.Connection();
                cn.Open(sAccessConnection, null, null, 0);
                cat.ActiveConnection = cn;

                //新建一个表
                ADOX.TableClass tbl = new ADOX.TableClass();
                tbl.ParentCatalog = cat;
                tbl.Name          = tableName;

                int size = mdbHead.Count;

                for (int i = 0; i < size; i++)
                {
                    //增加一个文本字段
                    ADOX.ColumnClass col2 = new ADOX.ColumnClass();
                    ADOX.IndexClass  ind2 = new ADOX.IndexClass();
                    col2.ParentCatalog = cat;
                    col2.Name          = mdbHead[i].ToString();//列的名称

                    col2.Properties["Jet OLEDB:Allow Zero Length"].Value = false;
                    col2.DefinedSize = 50;
                    if (i == 0)
                    {
                        //   col2.Type = ADOX.DataTypeEnum.adSingle;
                        //   col2.Type = ADOX.DataTypeEnum.adInteger;
                        //   col2.Properties["AutoIncrement"].Value = true;
                        tbl.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "通道");
                    }
                    col2.SortOrder = ADOX.SortOrderEnum.adSortAscending;
                    //   col2.DefinedSize = 20;
                    //  col2.Type = ADOX.DataTypeEnum.adGUID;
                    tbl.Columns.Append(col2, ADOX.DataTypeEnum.adWChar, 50);

                    //    tbl.Indexes.Append(col2 as );
                    //            tbl.Columns.Append(col2, ADOX.KeyTypeEnum.adKeyPrimary, 500);
                }
                cat.Tables.Append(tbl);       //这句把表加入数据库(非常重要)

                tbl = null;
                cat = null;
                cn.Close();
                return(true);
            }
            catch (Exception t)
            {
                MessageBox.Show(t.Message);
                return(false);
            }
        }
コード例 #30
0
        //创建数据库
        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();
        }
コード例 #31
0
 public static void CloseAdo(ADODB.Connection db)
 {
     // close the connection if it exists
     if (db != null && db.State != 0)
     {
         try {
             db.Close();
         } catch (Exception) { }
     }
 }
コード例 #32
0
 //--------------------------------------------------------------------------------------------
 /// <summary>
 /// This method is called by the service manager and will allow the server to gracefully
 /// stop listening as well as warn any clients as to why they are being disconnected.
 /// </summary>
 protected override void OnStop()
 {
     //server.KillClients();
     server.StopListening();
     try
     {
         db.Close();
     }
     catch { }
 }
コード例 #33
0
        //Lagerbestand
        private void metroComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ADODB.Connection cn = new ADODB.Connection();
            ADODB.Recordset  rs = new ADODB.Recordset();
            try {
                cn.Open(cnStr);
                string periode = metroComboBox1.Text;

                if (periode == "0")
                {
                    rs.Open("Select Startmenge, Artikelnummer, Startpreis From Artikelstammdaten", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);

                    int i = 0;
                    metroGrid5.Rows.Clear();
                    while (!rs.EOF)
                    {
                        metroGrid5.Rows.Add();
                        metroGrid5.Rows[i].Cells["period"].Value      = Convert.ToInt32(periode);
                        metroGrid5.Rows[i].Cells["id"].Value          = Convert.ToInt32(rs.Fields["Artikelnummer"].Value);
                        metroGrid5.Rows[i].Cells["actualStock"].Value = Convert.ToInt32(rs.Fields["Startmenge"].Value);
                        metroGrid5.Rows[i].Cells["actualPrice"].Value = Convert.ToDouble(rs.Fields["Startpreis"].Value);
                        //metroGrid5.Rows[i].Cells["stockValue"].Value = ;
                        rs.MoveNext();
                        i++;
                    }
                }
                else
                {
                    rs.Open("Select * From warehousestock_article where period ='" + periode + "'", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);

                    int i = 0;
                    metroGrid5.Rows.Clear();
                    while (!rs.EOF)
                    {
                        metroGrid5.Rows.Add();
                        metroGrid5.Rows[i].Cells["period"].Value      = Convert.ToInt32(rs.Fields["period"].Value);
                        metroGrid5.Rows[i].Cells["id"].Value          = Convert.ToInt32(rs.Fields["id"].Value);
                        metroGrid5.Rows[i].Cells["actualStock"].Value = Convert.ToInt32(rs.Fields["amount"].Value);
                        metroGrid5.Rows[i].Cells["actualPrice"].Value = Convert.ToDouble(rs.Fields["price"].Value);
                        metroGrid5.Rows[i].Cells["stockValue"].Value  = Convert.ToDouble(rs.Fields["stockValue"].Value);
                        rs.MoveNext();
                        i++;
                    }
                }
                rs.Close();
            }
            catch (Exception fehler)
            {
                Console.WriteLine("Ein Fehler ist aufgetreten", fehler);              //Try catch überprüfen....
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #34
0
        /// <summary>
        /// 建立 优惠劵 数据库
        /// </summary>
        public static void Coupons_InitDataBase()
        {
            // string sqlstr = "INSERT INTO WX_Coupons(CUserName, CUserPhone, CUserqq, WXOpenID)  VALUES   (N'" + CUserName + "',N'" + CUserPhone + "',N'" + CUserqq + "',N'" + Session["WXOpenID"] + "')";

            string PathDataBase = System.IO.Path.Combine(SYSTEMDIR, "USER_DIR\\SYSUSER\\Coupons\\db.dll");//"USER_DIR\\SYSUSER\\SYSSET\\" +
            if (System.IO.File.Exists(PathDataBase) == true )
            {
               return;
            }

            try
            {

                ADOX.Catalog catalog = new Catalog();
                catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PathDataBase + ";Jet OLEDB:Engine Type=5");

                ADODB.Connection cn = new ADODB.Connection();

                cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PathDataBase, null, null, -1);
                catalog.ActiveConnection = cn;

                if (true)
                {
                    ADOX.Table table = new ADOX.Table();
                    table.Name = "WX_Coupons";
                    ADOX.Column column = new ADOX.Column();
                    column.ParentCatalog = catalog;
                    column.Name = "WXOpenID";
                    column.Type = DataTypeEnum.adInteger;
                    column.DefinedSize = 7;
                    column.Properties["AutoIncrement"].Value = true;
                    table.Columns.Append(column, DataTypeEnum.adInteger, 7);
                    table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column, null, null);
              // string sqlstr = "INSERT INTO WX_Coupons(CUserName, CUserPhone, CUserqq, WXOpenID)  VALUES   (N'" + CUserName + "',N'" + CUserPhone + "',N'" + CUserqq + "',N'" + Session["WXOpenID"] + "')";
                    table.Columns.Append("CUserName", DataTypeEnum.adVarWChar, 200);
                    table.Columns.Append("CUserPhone", DataTypeEnum.adVarWChar, 200);
                    table.Columns.Append("CUserqq", DataTypeEnum.adVarWChar, 200);
                    catalog.Tables.Append(table);
                }
                cn.Close();
            }
            catch
            {

            }
        }
コード例 #35
0
ファイル: Program.cs プロジェクト: egil/alfac
 private static void AddTable(OleDbConnectionStringBuilder csb)
 {
     // check if table exists
     var con = new ADODB.Connection();
     con.Open(csb.ToString());
     var db = new ADOX.Catalog();
     db.ActiveConnection = con;
     try
     {
         var table = db.Tables[_logFileProcessor.TableName];
     }
     catch (COMException)
     {
         db.Tables.Append(_logFileProcessor.GetTable());
     }
     finally
     {
         con.Close();
     }
 }
コード例 #36
0
ファイル: DataBase.cs プロジェクト: szpaqq/SourceCode
        /// <summary>
        /// Saves information about XML Files into database
        /// </summary>
        /// <param name="filesArray">List with informations about XML Files</param>
        /// <returns>True if success</returns>
        public bool SaveFiles(XmlFile[] filesArray)
        {
            string strSQL;
            ADODB.Connection con = new ADODB.Connection();
            object obj = new object();

            try
            {
                con.Open(GenerateConnectionString(), "", "", 0);
            }
            catch (Exception)
            {
                return false;
            }

            for (int i = 0; i < filesArray.Length; i++)
            {
                strSQL = string.Format(NEW_XML_FILE,
                    filesArray[i].Id,
                    filesArray[i].Name,
                    filesArray[i].Content,
                    filesArray[i].TimeStamp);

                try
                {
                    con.Execute(strSQL, out obj, 0);
                }
                catch (Exception)
                {
                    //TODO: Error logging
                    con.Close();
                    return false;
                }
            }

            con.Close();
            return true;
        }
コード例 #37
0
ファイル: Columns.cs プロジェクト: attila3453/alsing
		private void LoadExtraDataForTable()
		{
			try
			{
				if(this._array.Count > 0)
				{
					ADODB.Connection cnn = new ADODB.Connection();
					ADOX.Catalog cat = new ADOX.Catalog();
    
					// Open the Connection
					cnn.Open(dbRoot.ConnectionString, null, null, 0);
					cat.ActiveConnection = cnn;

					ADOX.Columns cols = null;
					cols = cat.Tables[this.Table.Name].Columns;

					Column col = this._array[0] as Column;

					f_TypeName = new DataColumn("TYPE_NAME", typeof(string));
					col._row.Table.Columns.Add(f_TypeName);

					f_AutoKey  = new DataColumn("AUTO_INCREMENT", typeof(Boolean));
					col._row.Table.Columns.Add(f_AutoKey);

					f_AutoKeySeed		= new DataColumn("AUTO_KEY_SEED", typeof(System.Int32));
					col._row.Table.Columns.Add(f_AutoKeySeed);

					f_AutoKeyIncrement	= new DataColumn("AUTO_KEY_INCREMENT", typeof(System.Int32));
					col._row.Table.Columns.Add(f_AutoKeyIncrement);

					int count = this._array.Count;
					Column c = null;
					ADOX.Column cx = null;

					for( int index = 0; index < count; index++)
					{
						cx = cols[index];
						c  = (Column)this[cx.Name];

						string hyperlink = "False";

						try
						{
							hyperlink = cx.Properties["Jet OLEDB:Hyperlink"].Value.ToString();
						} 
						catch {}

						string name = cx.Name;

						Console.WriteLine("-----------------------------------------");
						foreach(ADOX.Property prop in cx.Properties)
						{
							Console.WriteLine(prop.Attributes.ToString());
							Console.WriteLine(prop.Name);
							if(null != prop.Value)
								Console.WriteLine(prop.Value.ToString());
						}

						c._row["TYPE_NAME"]      = hyperlink == "False" ? cx.Type.ToString() : "Hyperlink";

						try
						{
							if(c.Default == "GenGUID()")
							{
								c._row["AUTO_INCREMENT"] = Convert.ToBoolean(cx.Properties["Jet OLEDB:AutoGenerate"].Value);
							}
							else
							{
								c._row["AUTO_INCREMENT"] = Convert.ToBoolean(cx.Properties["Autoincrement"].Value);
								c._row["AUTO_KEY_SEED"]  = Convert.ToInt32(cx.Properties["Seed"].Value);
								c._row["AUTO_KEY_INCREMENT"]  = Convert.ToInt32(cx.Properties["Increment"].Value);
							}
						}
						catch {}
					}

					cnn.Close();
				}
			}
			catch {}
		}
コード例 #38
0
        /// <summary>
        /// 建立 大转盘 数据库
        /// </summary>
        public static void Turntable_InitDataBase()
        {
            string PathDataBase = System.IO.Path.Combine(SYSTEMDIR, "USER_DIR\\SYSUSER\\Turntable\\db.dll");//"USER_DIR\\SYSUSER\\SYSSET\\" +
            if (System.IO.File.Exists(PathDataBase) == true)
            {
                return;
            }

            try
            {

                ADOX.Catalog catalog = new Catalog();
                catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PathDataBase + ";Jet OLEDB:Engine Type=5");

                ADODB.Connection cn = new ADODB.Connection();

                cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PathDataBase, null, null, -1);
                catalog.ActiveConnection = cn;

                //     string Data1 = "CREATE TABLE WX_GGK( \r\n";
                //     Data1 += "ID int IDENTITY(1,1) NOT NULL,\r\n";
                //     Data1 += "Name nvarchar(200) NULL,\r\n";
                //     Data1 += "Cs int NULL\r\n";
                //     Data1 += ") ON PRIMARY\r\n";

                //            Data1 += "CREATE TABLE WX_GGK_JP(\r\n";
                //Data1 += "ID int IDENTITY(1,1) NOT NULL,\r\n";
                //Data1 += "Name nvarchar(200) NULL,\r\n";
                //Data1 += "Jp nvarchar(50) NULL,\r\n";
                //Data1 += "SJH nvarchar(50) NULL\r\n";
                //Data1 += ") ON PRIMARY\r\n";

                //     object dummy = Type.Missing;
                //     cn.Execute(Data1, out dummy, 0);
                  if (true)
                    {
                        ADOX.Table table = new ADOX.Table();
                        table.Name = "wx_dzp";
                        ADOX.Column column = new ADOX.Column();
                        column.ParentCatalog = catalog;
                        column.Name = "ID";
                        column.Type = DataTypeEnum.adInteger;
                        column.DefinedSize = 7;
                        column.Properties["AutoIncrement"].Value = true;
                        table.Columns.Append(column, DataTypeEnum.adInteger, 7);
                        table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column, null, null);

                        table.Columns.Append("Name", DataTypeEnum.adVarWChar, 200);
                        table.Columns.Append("Cs", DataTypeEnum.adInteger, 7);

                        catalog.Tables.Append(table);
                    }

                if (true)
                {
                    ADOX.Table table = new ADOX.Table();
                    table.Name = "wx_dzp_jp";
                    ADOX.Column column = new ADOX.Column();
                    column.ParentCatalog = catalog;
                    column.Name = "ID";
                    column.Type = DataTypeEnum.adInteger;
                    column.DefinedSize = 7;
                    column.Properties["AutoIncrement"].Value = true;
                    table.Columns.Append(column, DataTypeEnum.adInteger, 7);
                    table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column, null, null);

                    table.Columns.Append("Name", DataTypeEnum.adVarWChar, 200);
                    table.Columns.Append("Jp", DataTypeEnum.adVarWChar, 200);
                    table.Columns.Append("SJH", DataTypeEnum.adVarWChar, 200);

                    catalog.Tables.Append(table);
                }

                cn.Close();

            }
            catch
            {

            }
        }
コード例 #39
0
ファイル: Login.cs プロジェクト: xxxhycl2010/RBAC-1
        /// <summary>
        /// 创建新的信息数据库
        /// </summary>
        private void CreatDb()
        {
            string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dac.accdb";

            ADOX.Catalog catalog = new Catalog();
            catalog.Create(con);//创建新的数据库

            catalog.ActiveConnection();
            ADODB.Connection connection = new ADODB.Connection();
            connection.Open(con, null, null, -1);

            //新建主体信息数据表
            ADOX.Table table = new Table();
            table.Name = "主体信息表";

            ADOX.Column subjectName = new Column();//主体名称
            subjectName.Name = "主体名称";
            ADOX.Column pwd = new Column();//主体登录密码
            pwd.Name = "密码";
            ADOX.Column SubjectRegisterTime = new Column();//主体登录密码
            SubjectRegisterTime.Name = "注册时间";

            table.Columns.Append(subjectName);//将列添加到表中
            table.Columns.Append(pwd);
            table.Columns.Append(SubjectRegisterTime);
            catalog.Tables.Append(table);

            //新建角色信息数据表
             table = new Table();
            table.Name = "角色信息表";

            ADOX.Column RoleName = new Column();//角色名称
            RoleName.Name = "角色名称";

            ADOX.Column RoleRegisterTime= new Column();//角色注册时间
            RoleRegisterTime.Name = "创建时间";

            table.Columns.Append(RoleName);//将列添加到表中
            table.Columns.Append(RoleRegisterTime);
            catalog.Tables.Append(table);
            //新建角互斥色信息数据表
            table = new Table();
            table.Name = "互斥角色信息表";

            ADOX.Column ExclusionRoleName = new Column();//角色名称
            ExclusionRoleName.Name = "角色1名称";
            ADOX.Column ExclusionRoleName1 = new Column();//角色名称
            ExclusionRoleName1.Name = "角色2名称";

            table.Columns.Append(ExclusionRoleName);//将列添加到表中
            table.Columns.Append(ExclusionRoleName1);
            catalog.Tables.Append(table);

            //新建角色关系信息数据表
            table = new Table();
            table.Name = "角色关系信息表";
            ADOX.Column FatherRoleName = new Column();//角色名称
            FatherRoleName.Name = "父角色名称";
            ADOX.Column ChildRoleName = new Column();//角色名称
            ChildRoleName.Name = "子角色名称";
            table.Columns.Append(FatherRoleName);//将列添加到表中
            table.Columns.Append(ChildRoleName);
            catalog.Tables.Append(table);

            //新建权限信息表
            table = new Table();
            table.Name = "权限信息表";
            ADOX.Column PermissionName = new Column();//权限名称
            PermissionName.Name = "权限名称";
            ADOX.Column PermissionRegisterTime = new Column();//权限创建注册时间
            PermissionRegisterTime.Name = "创建时间";

            table.Columns.Append(PermissionName);//将列添加到表中
            table.Columns.Append(PermissionRegisterTime);
            catalog.Tables.Append(table);

            //新建用户角色指派信息表
            table = new Table();
            table.Name = "用户-角色指派信息表";
            ADOX.Column UserName = new Column();//用户名称
            UserName.Name = "用户名称";
              RoleName = new Column();//角色名称
            RoleName.Name = "角色名称";

            table.Columns.Append(UserName);//将列添加到表中
            table.Columns.Append(RoleName);
            catalog.Tables.Append(table);

            //新建角色到权限的指派信息表

            table = new Table();
            table.Name = "角色-权限指派信息表";
            RoleName = new Column();//角色名称
            RoleName.Name = "角色名称";
            PermissionName = new Column();//权限名称
            PermissionName.Name = "权限名称";

            table.Columns.Append(RoleName);
            table.Columns.Append(PermissionName);
            catalog.Tables.Append(table);

            //新建注册管理表
            table = new Table();
            table.Name = "注册管理表";
            ADOX.Column subject_Name1 = new Column();//客体名称
            subject_Name1.Name = "主体名称";
            ADOX.Column time = new Column();//客体名称
            time.Name = "注册时间";
            ADOX.Column pwd1 = new Column();//客体名称
            pwd1.Name = "密码";

            table.Columns.Append(subject_Name1);
            table.Columns.Append(time);
            table.Columns.Append(pwd1);
            catalog.Tables.Append(table);

            connection.Close();//关闭连接
        }
コード例 #40
0
ファイル: DataBase.cs プロジェクト: szpaqq/SourceCode
        /// <summary>
        /// Saves TAGs list into database
        /// </summary>
        /// <param name="tagsArray">List of TAGs</param>
        /// <returns>True if success</returns>
        public bool SaveTags(Tag[] tagsArray)
        {
            string strSQL;
            ADODB.Connection con = new ADODB.Connection();
            object obj = new object();

            try
            {
                con.Open(GenerateConnectionString(), "", "", 0);
            }
            catch (Exception)
            {
                //TODO: Error logging
                return false;
            }

            for (int i = 0; i < tagsArray.Length; i++)
            {
                strSQL = string.Format(NEW_TAG,
                    tagsArray[i].Id,
                    tagsArray[i].Name);

                try
                {
                    con.Execute(strSQL, out obj, 0);
                }
                catch (Exception)
                {
                    //TODO: Error logging
                    con.Close();
                    return false;
                }
            }

            con.Close();
            return true;
        }
コード例 #41
0
ファイル: DataBase.cs プロジェクト: szpaqq/SourceCode
        /// <summary>
        /// Removes all entries from given table
        /// </summary>
        /// <param name="table">Table name</param>
        /// <returns>True if success</returns>
        public bool DeleteAllData(string table)
        {
            string strSQL = string.Format(DELETE_ALL, table);
            ADODB.Connection con = new ADODB.Connection();
            object obj = new object();

            try
            {
                con.Open(GenerateConnectionString(), "", "", 0);
            }
            catch (Exception)
            {
                //TODO: Error logging
                return false;
            }

            try
            {
                con.Execute(strSQL, out obj, 0);
            }
            catch (Exception)
            {
                //TODO: Error logging
                con.Close();
                return false;
            }

            con.Close();
            return true;
        }
コード例 #42
0
ファイル: Program.cs プロジェクト: rmount/onelan
        // Output data to xml
        public static Boolean bExportDataToXML(String sDatabaseLocation, Boolean bDebug)
        {
            clsLog clsLog_ = new clsLog(msLogFile, msVersionData);
            clsError clsError_ = new clsError();

            ADODB.Connection conn = new ADODB.Connection();
            ADODB.Recordset rs = new ADODB.Recordset();

            clsLog_.mLog(Constants.gcInfo, "Exporting data to xml ...");

            String sOneLanPropertyfile = sDatabaseLocation + "\\xml\\OneLanProperty.xml";
            String sOneLanAccomfile = sDatabaseLocation + "\\xml\\OneLanAccom.xml";

            if (bDebug) { clsLog_.mLog(Constants.gcInfo, sIndent + "onelan.bExportDataToXML, sOneLanPropertyfile = " + sOneLanPropertyfile); }
            if (bDebug) { clsLog_.mLog(Constants.gcInfo, sIndent + "onelan.bExportDataToXML, sOneLanAccomfile = " + sOneLanAccomfile); }

            try
            {
                // Open connection to database
                conn.Open(gcDSN + sDatabaseLocation + "\\" + gsOneLanDatabase);

                // Remove previous versions of the files
                if (File.Exists(sOneLanPropertyfile)) {File.Delete(sOneLanPropertyfile);}
                if (File.Exists(sOneLanAccomfile)) {File.Delete(sOneLanAccomfile);}

                // Open the recordset
                rs.Open("SELECT * FROM Property", conn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, -1);
                rs.Save(sOneLanPropertyfile, ADODB.PersistFormatEnum.adPersistXML);
                rs.Close();

                rs.Open("SELECT * FROM Accom", conn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, -1);
                rs.Save(sOneLanAccomfile, ADODB.PersistFormatEnum.adPersistXML);
                rs.Close();

                conn.Close();

                return true;
            }
            catch (Exception e)
            {
               clsError_.mLogError("Problem exporting data to xml", "onelan", "bExportDataToXML", e, msVersionData, msLogFile, false);
               return false;
            }
        }
コード例 #43
0
ファイル: Program.cs プロジェクト: rmount/onelan
        //
        // Refresh data
        //
        public static Boolean bRefreshData(String sDatabaseLocation, Boolean bDebug)
        {
            clsLog clsLog_ = new clsLog(msLogFile, msVersionData);
            clsError clsError_ = new clsError();

            String sSql = null;
            ADODB.Connection conn = new ADODB.Connection();
            object RecordsAffected = null;

            try
            {

                clsLog_.mLog(Constants.gcInfo, "Refreshing data ...");

                if (bDebug) { clsLog_.mLog(Constants.gcInfo, sIndent + "onelan.bRefreshData, database =" + sDatabaseLocation +"\\" + gsOneLanDatabase); }
                // Open connection to database
                conn.Open(gcDSN + sDatabaseLocation + "\\" + gsOneLanDatabase);

                 //1.1 Purge accom table for properities no longer current
                sSql = "DELETE FROM accom a" +
                       " WHERE NOT EXISTS (" +
                       "  SELECT 1" +
                       "    FROM PropertyDetailsRC rc" +
                       "   WHERE rc.propid = a.propid" +
                       "     AND rc.sold =0 and pending = 0)";

                conn.Execute(sSql, out RecordsAffected, -1);

                                //1.2 Purge Property table for properities no longer current
                sSql = "DELETE FROM Property p" +
                        " WHERE NOT EXISTS (" +
                        "  SELECT 1" +
                        "    FROM PropertyDetailsRC rc" +
                        "   WHERE rc.propid = p.propid" +
                        "     AND rc.sold =0 AND pending =0)";
                conn.Execute(sSql, out RecordsAffected, -1);

                //1.3 Add new properties
                sSql = "INSERT INTO Property (" +
                        " PropID" +
                        ",PropertyAddress1" +
                        ",PropertyAddress2" +
                        ",PropertyAddress3" +
                        ",PropertyAddress4" +
                        ",PostCode" +
                        ",Price" +
                        ",OffersOverEtc" +
                        ",RCCWOffice" +
                        ",UnderOffer" +
                        ",ClosingDate )";

                sSql = sSql  + "SELECT " +
                        " rc.PropID" +
                        ",rc.PropertyAddress1" +
                        ",rc.PropertyAddress2" +
                        ",rc.PropertyAddress3" +
                        ",rc.PropertyAddress4" +
                        ",rc.PostCode" +
                        ",rc.Price" +
                        ",rc.OffersOverEtc" +
                        ",rc.RCCWOffice" +
                        ",iif(ISNULL(rc.OfferDate),0,1)" +
                        ",rc.ClosingDate" +
                        "  FROM PropertyDetailsRC rc" +
                        " WHERE rc.sold=0" +
                        "   AND pending =0" +
                        " AND NOT EXISTS (" +
                        "  SELECT 1" +
                        "    FROM Property p2" +
                        "   WHERE p2.propid = rc.propid)";
                conn.Execute(sSql, out RecordsAffected, -1);
                // UNderOffer
               // clsLog_.mLog("INFO", sSql);
               // Debug.WriteLine(" insert sql = " + sSql);

                //1.4 Update property details to ensure current with main system
                sSql = "UPDATE property p," +
                        "       PropertyDetailsRC rc  SET " +
                        "       p.PropertyAddress1 = rc.PropertyAddress1" +
                        "      ,p.PropertyAddress2 = rc.PropertyAddress2" +
                        "      ,p.PropertyAddress3 = rc.PropertyAddress3" +
                        "      ,p.PropertyAddress4 = rc.PropertyAddress4" +
                        "      ,p.PostCode= rc.PostCode" +
                        "      ,p.Price= rc.Price" +
                        "      ,p.OffersOverEtc= rc.OffersOverEtc" +
                        "      ,p.ClosingDate= rc.ClosingDate" +
                        "      ,p.UnderOffer  = iif(ISNULL(rc.OfferDate),0,1)" +
                        " WHERE p.Propid = rc.Propid" +
                        "   AND (" +
                        "       p.PropertyAddress1 <> rc.PropertyAddress1" +
                        "    OR p.PropertyAddress2 <> rc.PropertyAddress2" +
                        "    OR p.PropertyAddress3 <> rc.PropertyAddress3" +
                        "    OR p.PropertyAddress4 <> rc.PropertyAddress4" +
                        "    OR p.PostCode <> rc.PostCode" +
                        "    OR p.Price <> rc.Price" +
                        "    OR p.OffersOverEtc <> rc.OffersOverEtc" +
                        "    OR p.ClosingDate <> rc.ClosingDate" +
                        "    OR (p.UnderOffer= '0' AND rc.OfferDate IS NOT NULL)" +
                        " )";
              //  clsLog_.mLog("INFO", sSql);
                conn.Execute(sSql, out RecordsAffected, -1);
                // Fix the closing date
                //1.4.1 Update null closing date to 00:00:00

                sSql = "Update Property" +
                " Set closingdate = '00:00:00'" +
                " Where closingdate Is Null or format(closingDate,'dd-mmm-yyyy')=''";
              	            conn.Execute(sSql, out RecordsAffected, -1);

                //1.4 Add new ACC
                sSql = "  INSERT INTO ACCOM (Propid,Accom, Website)" +
                        " SELECT rca.Propid,rca.Accom, rca.Website" +
                        "   FROM ACCOMRC rca," +
                        "        property p " +
                        " WHERE p.propid= rca.propid" +
                        " AND NOT EXISTS (" +
                        "     SELECT 1" +
                        "       FROM accom a" +
                        "      WHERE a.propid = p.propid)";
              	            conn.Execute(sSql, out RecordsAffected, -1);

                conn.Close();

                return true;
            }
            catch (Exception e)
            {
                clsError_.mLogError("Problem running onelan interface", "onelan", "bRefreshData", e, msVersionData, msLogFile,false);
                return false;
            }
        }
コード例 #44
0
ファイル: Program.cs プロジェクト: zealoussnow/OneCode
    static void Main(string[] args)
    {
        ADODB.Connection conn = null;
        ADODB.Recordset rs = null;

        try
        {
            ////////////////////////////////////////////////////////////////////////////////
            // 连接数据源.
            //

            Console.WriteLine("正在连接数据库 ...");

            // 获取连接字符串
            string connStr = string.Format("Provider=SQLOLEDB;Data Source={0};Initial Catalog={1};Integrated Security=SSPI",
                ".\\sqlexpress", "SQLServer2005DB");

            // 打开连接
            conn = new ADODB.Connection();
            conn.Open(connStr, null, null, 0);

            ////////////////////////////////////////////////////////////////////////////////
            // 编写并执行ADO命令.
            // 可以是SQL指令(SELECT/UPDATE/INSERT/DELETE),或是调用存储过程.
            // 此处是一个INSERT命令示例.
            //

            Console.WriteLine("将一条记录插入表CountryRegion中...");

            // 1. 生成一个Command对象
            ADODB.Command cmdInsert = new ADODB.Command();

            // 2. 将连接赋值于命令
            cmdInsert.ActiveConnection = conn;

            // 3. 设置命令文本
            //  SQL指令或者存储过程名
            cmdInsert.CommandText = "INSERT INTO CountryRegion(CountryRegionCode, Name, ModifiedDate)"
                + " VALUES (?, ?, ?)";

            // 4. 设置命令类型
            // ADODB.CommandTypeEnum.adCmdText 用于普通的SQL指令;
            // ADODB.CommandTypeEnum.adCmdStoredProc 用于存储过程.
            cmdInsert.CommandType = ADODB.CommandTypeEnum.adCmdText;

            // 5. 添加参数

            //  CountryRegionCode (nvarchar(20)参数的添加
            ADODB.Parameter paramCode = cmdInsert.CreateParameter(
                "CountryRegionCode",                        // 参数名
                ADODB.DataTypeEnum.adVarChar,               // 参数类型 (nvarchar(20))
                ADODB.ParameterDirectionEnum.adParamInput,  // 参数类型
                20,                                         // 参数的最大长度
                "ZZ"+DateTime.Now.Millisecond);             // 参数值
            cmdInsert.Parameters.Append(paramCode);

            // Name (nvarchar(200))参数的添加
            ADODB.Parameter paramName = cmdInsert.CreateParameter(
                "Name",                                     // 参数名
                ADODB.DataTypeEnum.adVarChar,               // 参数类型 (nvarchar(200))
                ADODB.ParameterDirectionEnum.adParamInput,  // 参数传递方向
                200,                                        // 参数的最大长度
                "Test Region Name");                        // 参数值
            cmdInsert.Parameters.Append(paramName);

            // ModifiedDate (datetime)参数的添加
            ADODB.Parameter paramModifiedDate = cmdInsert.CreateParameter(
                "ModifiedDate",                             // 参数名
                ADODB.DataTypeEnum.adDate,                  // 参数类型 (datetime)
                ADODB.ParameterDirectionEnum.adParamInput,  // 参数传递方向
                -1,                                         // 参数的最大长度 (datetime忽视该值)
                DateTime.Now);                              // 参数值
            cmdInsert.Parameters.Append(paramModifiedDate);

            // 6. 执行命令
            object nRecordsAffected = Type.Missing;
            object oParams = Type.Missing;
            cmdInsert.Execute(out nRecordsAffected, ref oParams,
                (int)ADODB.ExecuteOptionEnum.adExecuteNoRecords);

            ////////////////////////////////////////////////////////////////////////////////
            // 使用Recordset对象.
            // http://msdn.microsoft.com/en-us/library/ms681510.aspx
            // Recordset表示了数据表中记录或执行命令获得的结果的集合。
            // 在任何时候, Recordset对象都指向集合中的单条记录,并将
            // 该记录作为它的当前记录。
            //

            Console.WriteLine("列出表CountryRegion中的所有记录");

            // 1. 生成Recordset对象
            rs = new ADODB.Recordset();

            // 2. 打开Recordset对象
            string strSelectCmd = "SELECT * FROM CountryRegion"; // WHERE ...
            rs.Open(strSelectCmd,                                // SQL指令/表,视图名 /
                                                                 // 存储过程调用 /文件名
                conn,                                            // 连接对象/连接字符串
                ADODB.CursorTypeEnum.adOpenForwardOnly,          // 游标类型. (只进游标)
                ADODB.LockTypeEnum.adLockOptimistic,	         // 锁定类型. (仅当需要调用
                                                                 // 更新方法时,才锁定记录)
                (int)ADODB.CommandTypeEnum.adCmdText);	         // 将第一个参数视为SQL命令
                                                                 // 或存储过程.

            // 3. 通过向前移动游标列举记录

            // 移动到Recordset中的第一条记录
            rs.MoveFirst();
            while (!rs.EOF)
            {
                // 当在表中定义了一个可空字段,需要检验字段中的值是否为DBNull.Value.
                string code = (rs.Fields["CountryRegionCode"].Value == DBNull.Value) ?
                    "(DBNull)" : rs.Fields["CountryRegionCode"].Value.ToString();

                string name = (rs.Fields["Name"].Value == DBNull.Value) ?
                    "(DBNull)" : rs.Fields["Name"].Value.ToString();

                DateTime modifiedDate = (rs.Fields["ModifiedDate"].Value == DBNull.Value) ?
                    DateTime.MinValue : (DateTime)rs.Fields["ModifiedDate"].Value;

                Console.WriteLine(" {2} \t{0}\t{1}", code, name, modifiedDate.ToString("yyyy-MM-dd"));

                // 移动到下一条记录
                rs.MoveNext();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("应用程序出现错误: {0}", ex.Message);
            if (ex.InnerException != null)
                Console.WriteLine("描述: {0}", ex.InnerException.Message);
        }
        finally
        {
            ////////////////////////////////////////////////////////////////////////////////
            // 退出前清理对象.
            //

            Console.WriteLine("正在关闭连接 ...");

            // 关闭record set,当它处于打开状态时
            if (rs != null && rs.State == (int)ADODB.ObjectStateEnum.adStateOpen)
                rs.Close();

            // 关闭数据库连接,当它处于打开状态时
            if (conn != null && conn.State == (int)ADODB.ObjectStateEnum.adStateOpen)
                conn.Close();
        }
    }
コード例 #45
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            ADODB.Connection objCon;
            DialogResult update;
            string[,] argArray;
            object[,] idxUpdate;
            object[] rtnList;
            object[] exTest;
            int numTests;
            string tstList;
            string argID;
            string itmList;
            string msgString;
            string tstID;
            string strCon;
            string strSQL;

            objCon = new ADODB.Connection();
            itmList = "";
            tstList = "";
            strCon = "driver={MySQL ODBC 5.1 Driver};server=107.22.232.228;uid=qa_people;pwd=thehandcontrols;" +
                "database=functional_test_data;option=3";

            //get the number of checkboxes that are checked from dbUpdater form
            idxUpdate = chkBoxNumChecked(chkArgument);

            for (int j = 0; j < idxUpdate.GetLength(0); j++)
                itmList = itmList + idxUpdate[j, 0] + "\t" + idxUpdate[j, 1] + "\r\n";

            //dimension an array for the arguments will be going into the database
            argArray = new string[idxUpdate.GetLength(0), 2];

            for (int z = 0; z < argArray.GetLength(0); z++)
            {
                argArray[z, 0] = idxUpdate[z, 0].ToString();
                argArray[z, 1] = lblArgument[Convert.ToInt32(idxUpdate[z, 0])].Text;
            }

            //get the test ID
            strSQL = "SELECT id FROM test WHERE name = '" + tstname + "'";
            rtnList = db_access(strSQL);
            tstID = rtnList[0].ToString();

            //get the argument set id
            strSQL = "SELECT argument_set_id FROM step WHERE (test_id = '" + tstID + "' AND number = " + thsStep[0] + ")";
            rtnList = db_access(strSQL);
            argID = rtnList[0].ToString();

            strSQL = "SELECT COUNT(*) FROM step WHERE argument_set_id = '" + argID + "'";
            rtnList = db_access(strSQL);
            numTests = Convert.ToInt32(rtnList[0]);

            if (numTests <= 1)
            {
                if (numTests != 0)
                {
                    //get the argument set id
                    strSQL = "SELECT test_id FROM step WHERE argument_set_id = '" + argID + "'";
                    rtnList = db_access(strSQL);
                }
            }
            else
            {
                strSQL = "SELECT test_id FROM step WHERE (argument_set_id = '" + argID + "' AND test_id <> (SELECT id FROM test WHERE name = '" + tstname + "'))";
                rtnList = db_access(strSQL);
            }

            if (rtnList.Length != 0)
            {
                for (int k = 0; k < rtnList.Length; k++)
                {
                    strSQL = "SELECT name from test WHERE id = '" + rtnList[k] + "'";
                    exTest = db_access(strSQL);
                    tstList = tstList + exTest[0] + "\r\n";
                }
                msgString = "You will be updating Step " + thsStep[0] + " of the " + tstname +
                    " test.\r\nThe following data items will be updated\r\n\r\nIndex#\tData Item\r\n" + itmList +
                    "\r\nYou will not be able to undo these changes once they are done. " +
                    "The argument set that you are updating is also used in the following tests:\r\n\r\n" + tstList +
                    "\r\nAre you sure you want to Continue?\r\n\r\nPress 'Yes' to Update. Press 'No' to exit";
            }
            else
            {
                msgString = "You will be updating Step " + thsStep[0] + " of the " + tstname +
                    " test.\r\nThe following data items will be updated\r\n\r\nIndex#\tData Item\r\n" + itmList +
                    "\r\nYou will not be able to undo these changes once they are done. " +
                    "The argument set that you are updating is not used in any other tests>" +
                    "\r\nAre you sure you want to Continue?\r\n\r\nPress 'Yes' to Update. Press 'No' to exit";
            }
            update = MessageBox.Show(msgString, "Database Updater", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (update == DialogResult.Yes)
            {
                objCon.Open(strCon);

                for (int x = 0; x < argArray.GetLength(0); x++)
                {
                    strSQL = "UPDATE argument SET value='" + argArray[x, 1] + "' WHERE argument_set_id = '" + argID + "' AND seq = "
                        + (Convert.ToInt32(argArray[x, 0]) + 1).ToString();
                    objCon.Execute(strSQL, out missing, 0);
                }

                objCon.Close();

                MessageBox.Show("Database rows updated.\r\nDone! ", "Database Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();
            }
        }
コード例 #46
0
		override internal void LoadAll()
		{
			DataTable metaData = CreateDataTable();

			ADODB.Connection cnn = new ADODB.Connection();
			ADOX.Catalog cat = new ADOX.Catalog();
    
			// Open the Connection
			cnn.Open(dbRoot.ConnectionString, null, null, 0);
			cat.ActiveConnection = cnn;

			ADOX.Procedure proc = cat.Procedures[this.Procedure.Name];

			ADODB.Command cmd = proc.Command as ADODB.Command;
       
			// Retrieve Parameter information
			cmd.Parameters.Refresh();

			if(cmd.Parameters.Count > 0)
			{
				int ordinal = 0;

				foreach(ADODB.Parameter param in cmd.Parameters)
				{
					DataRow row = metaData.NewRow();

					string hyperlink = "False";

					try
					{
						hyperlink = param.Properties["Jet OLEDB:Hyperlink"].Value.ToString();
					} 
					catch {}

					row["TYPE_NAME"]                = hyperlink == "False" ? param.Type.ToString() : "Hyperlink";

					row["PROCEDURE_CATALOG"]		= this.Procedure.Database;
					row["PROCEDURE_SCHEMA"]			= null;
					row["PROCEDURE_NAME"]			= this.Procedure.Name;
					row["PARAMETER_NAME"]			= param.Name;
					row["ORDINAL_POSITION"]			= ordinal++;
					row["PARAMETER_TYPE"]			= param.Type;//.ToString();
					row["PARAMETER_HASDEFAULT"] 	= false;
					row["PARAMETER_DEFAULT"]    	= null;
					row["IS_NULLABLE"]				= false;
					row["DATA_TYPE"]				= param.Type;//.ToString();
					row["CHARACTER_MAXIMUM_LENGTH"]	= 0;
					row["CHARACTER_OCTET_LENGTH"]	= 0;
					row["NUMERIC_PRECISION"]		= param.Precision;
					row["NUMERIC_SCALE"]			= param.NumericScale;
					row["DESCRIPTION"]				= "";
				//	row["TYPE_NAME"]				= "";
					row["LOCAL_TYPE_NAME"]			= "";

					metaData.Rows.Add(row);
				}
			}

			cnn.Close();

			base.PopulateArray(metaData);
 		}
コード例 #47
0
ファイル: frmUpdateDayEnd.cs プロジェクト: nodoid/PointOfSale
        private bool buildPath1(ref string lPath)
        {
            bool functionReturnValue = false;
            ADOX.Catalog cat = default(ADOX.Catalog);
            ADOX.Table tbl = default(ADOX.Table);
            ADODB.Recordset rs = default(ADODB.Recordset);
            ADODB.Connection cn = new ADODB.Connection();
            string lFile = null;
            string holdfile = null;
            string[] lArray = null;
            short x = 0;
            Scripting.FileSystemObject fso = new Scripting.FileSystemObject();
            string lDir = null;
            cat = new ADOX.Catalog();
            tbl = new ADOX.Table();
             // ERROR: Not supported in C#: OnErrorStatement

            Cursor = System.Windows.Forms.Cursors.WaitCursor;

            if (modReport.cnnDBreport == null) {
            } else {
                cat.let_ActiveConnection(modReport.cnnDBreport);
                foreach ( tbl in cat.Tables) {
                    if (tbl.Type == "LINK") {
                        System.Windows.Forms.Application.DoEvents();
                        tbl.Properties("Jet OLEDB:Link Datasource").Value = modRecordSet.serverPath + "pricing.mdb";
                        //Replace(LCase(tbl.Properties("Jet OLEDB:Link Datasource")), LCase("C:\4posServer\"), serverPath)
                    }
                }
                cat = null;
                cn.Close();
                cn = null;
                cat = new ADOX.Catalog();
            }

            System.Windows.Forms.Application.DoEvents();
            Cursor = System.Windows.Forms.Cursors.Default;
            functionReturnValue = true;
            return functionReturnValue;
            buildPath_Error:
            Cursor = System.Windows.Forms.Cursors.Default;
            Interaction.MsgBox(Err().Description);
            functionReturnValue = false;
            return functionReturnValue;
        }
コード例 #48
0
ファイル: DataBase.cs プロジェクト: szpaqq/SourceCode
        /// <summary>
        /// Saves relations between TAGs and XML rows
        /// </summary>
        /// <param name="relationsArray">List with TAG IDs and XML FIELD IDs</param>
        /// <returns>True if success</returns>
        public bool SaveRelations(XmlTagRelation[] relationsArray)
        {
            string strSQL;
            ADODB.Connection con = new ADODB.Connection();
            object obj = new object();

            try
            {
                con.Open(GenerateConnectionString(), "", "", 0);
            }
            catch (Exception)
            {
                //TODO: Error logging
                return false;
            }

            for (int i = 0; i < relationsArray.Length; i++)
            {
                strSQL = string.Format(NEW_XML_TAG_RELATION,
                    relationsArray[i].TagID,
                    relationsArray[i].XmlFileID);

                try
                {
                    con.Execute(strSQL, out obj, 0);
                }
                catch (Exception)
                {
                    //TODO: Error logging
                    con.Close();
                    return false;
                }
            }

            con.Close();
            return true;
        }
コード例 #49
0
 public void TestFillDataTableByNameWithADODBRecordSet()
 {
     OleDbDataAdapter adapter = new OleDbDataAdapter();
     DataSet stuDS = new DataSet();
     DataTable stuTable = new DataTable("student");
     stuTable.Columns.Add("id", typeof(int));
     stuTable.Columns.Add("name", typeof(string));
     stuDS.Tables.Add(stuTable);
     //Use ADO objects from ADO library (msado15.dll) imported
     //  as.NET library ADODB.dll using TlbImp.exe
     ADODB.Connection adoConn = new ADODB.Connection();
     ADODB.Recordset adoRS = new ADODB.Recordset();
     adoConn.Open("Provider=CUBRIDProvider;Location=test-db-server;Data Source=demodb;User Id=dba;Port=30000", "", "", -1);
     adoRS.Open("SELECT * FROM student", adoConn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly, 1);
     int fillRowCount = adapter.Fill(stuDS, adoRS, "student"); //This method implicitly calls Close on the ADO object when the fill operation is complete.
     //adoRS.Close();
     adoConn.Close();
     Assert.AreEqual(3, fillRowCount);
     Assert.AreEqual(3, stuTable.Rows.Count);
 }
コード例 #50
0
 public void TestRefreshDataTableWithADODBRecordSet_Schema()
 {
     OleDbDataAdapter adapter = new OleDbDataAdapter();
     adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
     DataSet stuDS = new DataSet();
     DataTable stuTable = new DataTable("student");
     stuDS.Tables.Add(stuTable);
     //Use ADO objects from ADO library (msado15.dll) imported
     //  as.NET library ADODB.dll using TlbImp.exe
     ADODB.Connection adoConn = new ADODB.Connection();
     ADODB.Recordset adoRS = new ADODB.Recordset();
     adoConn.Open("Provider=CUBRIDProvider;Location=test-db-server;Data Source=demodb;User Id=dba;Port=30000", "", "", -1);
     adoRS.Open("SELECT * FROM student", adoConn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly, 1);
     adapter.Fill(stuTable, adoRS);
     adoRS.Requery(0);
     int refreshRowCount = adapter.Fill(stuTable, adoRS); // This method does not call Close on the ADO object when the fill operation is complete.
     adoRS.Close();
     adoConn.Close();
     Assert.IsNotNull(stuTable.PrimaryKey);
     Assert.AreEqual(3, refreshRowCount);
 }
コード例 #51
0
ファイル: Columns.cs プロジェクト: attila3453/alsing
		private void LoadExtraDataForView()
		{
			try
			{
				if(this._array.Count > 0)
				{
					ADODB.Connection cnn = new ADODB.Connection();
					ADODB.Recordset rs = new ADODB.Recordset();
					ADOX.Catalog cat = new ADOX.Catalog();
    
					// Open the Connection
					cnn.Open(dbRoot.ConnectionString, null, null, 0);
					cat.ActiveConnection = cnn;

					rs.Source = cat.Views[this.View.Name].Command;
					rs.Fields.Refresh();
					ADODB.Fields flds = rs.Fields;

					Column col = this._array[0] as Column;

					f_TypeName = new DataColumn("TYPE_NAME", typeof(string));
					col._row.Table.Columns.Add(f_TypeName);

					f_AutoKey  = new DataColumn("AUTO_INCREMENT", typeof(Boolean));
					col._row.Table.Columns.Add(f_AutoKey);

					Column c = null;
					ADODB.Field fld = null;

					int count = this._array.Count;
					for( int index = 0; index < count; index++)
					{
						fld = flds[index];
						c   = (Column)this[fld.Name];

						c._row["TYPE_NAME"]      = fld.Type.ToString();
						c._row["AUTO_INCREMENT"] = false;
					}

					rs.Close();
					cnn.Close();
				}
			}
			catch {}
		}
コード例 #52
0
ファイル: AccessHelp.cs プロジェクト: zformular/ValueHelper
        public Boolean CreateTable(String tableName, params ASColumn[] columns)
        {
            if (!CheckParams())
                throw new ArgumentNullException("请先绑定文件名");

            if (!File.Exists(base.FileName))
                throw new ArgumentNullException("文件不存在");

            if (String.IsNullOrEmpty(tableName))
                return false;
            try
            {
                ADOX.Catalog catalog = new Catalog();
                ADODB.Connection conn = new ADODB.Connection();
                conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + base.FileName, null, null, -1);
                catalog.ActiveConnection = conn;

                ADOX.Table table = new Table();
                table.Name = tableName;

                for (int i = 0; i < columns.Length; i++)
                {
                    ADOX.Column column = new Column();
                    column.ParentCatalog = catalog;
                    column.Name = columns[i].Name;
                    column.Type = columns[i].Type;
                    column.Attributes = columns[i].Attribute;
                    column.DefinedSize = columns[i].DefinedSize;
                    table.Columns.Append(column, column.Type, column.DefinedSize);
                    if (columns[i].Key != null)
                        table.Keys.Append(columns[i].Name + columns[i].Key.Type, columns[i].Key.Type, column, null, null);
                }
                catalog.Tables.Append(table);

                conn.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }