コード例 #1
0
        public void GetFields(Connection cnt)
        {
            System.Data.DataTable schemaColumn;
            fields  = new FieldList();
            Indexes = null;
            //
            //=====================================================
            dbWrapper db = new dbWrapper();

            db.CreateCommand((Connection)cnt.Clone());
            EPField fld;

            if (cnt.IsOleDb)
            {
                db.SetCommandText(TableName);
                db.SetCommandType(System.Data.CommandType.TableDirect);
            }
            else
            {
                db.SetCommandText("SELECT * FROM " + DatabaseEditUtil.SepBegin(cnt.NameDelimiterStyle) + TableName + DatabaseEditUtil.SepEnd(cnt.NameDelimiterStyle));
                db.SetCommandType(System.Data.CommandType.Text);
            }
            try
            {
                if (cnt.IsOleDb || cnt.IsMSSQL)
                {
                    db.OpenReader(System.Data.CommandBehavior.KeyInfo);
                }
                else
                {
                    db.OpenReader(System.Data.CommandBehavior.SchemaOnly);
                }
                schemaColumn = db.GetSchemaTable();
                db.CloseReader();
                db.Close();
                if (schemaColumn != null)
                {
                    for (int i = 0; i < schemaColumn.Rows.Count; i++)
                    {
                        fld = EPField.MakeFieldFromColumnInfo(i, schemaColumn.Rows[i]);
                        if (!string.IsNullOrEmpty(fld.Name))
                        {
                            fld.FromTableName = TableName;
                            fields.AddField(fld);
                        }
                    }
                }
            }
            catch (Exception er)
            {
                FormLog.NotifyException(true, er);
            }
            finally
            {
                db.CloseReader();
                db.Close();
            }
        }
コード例 #2
0
 public void MakeCommand(string table, FieldList rowID, Connection cn)
 {
     if (fields.Count > 0)
     {
         int i;
         rowIDFields = rowID;
         //================================
         cmdUpdates = new DbCommand[fields.Count];
         for (int k = 0; k < fields.Count; k++)
         {
             cmdUpdates[k] = cn.CreateCommand();
             StringBuilder sSQL = new StringBuilder();
             sSQL.Append(QueryParser.SQL_Update());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(table);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append(QueryParser.SQL_Set());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(fields[k].Name);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append("=?");
             sSQL.Append(QueryParser.SQL_Where());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(rowIDFields[0].Name);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append("=? ");
             for (i = 1; i < rowIDFields.Count; i++)
             {
                 sSQL.Append(QueryParser.SQL_And());
                 sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
                 sSQL.Append(rowIDFields[i].Name);
                 sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
                 sSQL.Append("=?");
             }
             cmdUpdates[k].CommandText = sSQL.ToString();
             DbParameter pam = cmdUpdates[k].CreateParameter();
             pam.ParameterName = fields[k].Name;
             pam.DbType        = ValueConvertor.OleDbTypeToDbType(fields[k].OleDbType);
             pam.Size          = fields[k].DataSize;
             pam.SourceColumn  = fields[k].Name;
             cmdUpdates[k].Parameters.Add(pam);
             for (i = 0; i < rowIDFields.Count; i++)
             {
                 pam = cmdUpdates[k].CreateParameter();
                 pam.ParameterName = rowIDFields[i].Name;
                 pam.DbType        = ValueConvertor.OleDbTypeToDbType(rowIDFields[i].OleDbType);
                 pam.Size          = rowIDFields[i].DataSize;
                 pam.SourceColumn  = rowIDFields[i].Name;
                 cmdUpdates[k].Parameters.Add(pam);
             }
         }
     }
 }
コード例 #3
0
        public void GetFields(Connection cnt)
        {
            int i;

            System.Data.DataTable schemaColumn = null;
            fields = new FieldList();
            if (cnt.IsOdbc)
            {
                return;
            }
            //=====================================================
            EPField   fld;
            dbWrapper db = new dbWrapper();

            db.CreateCommand(cnt);
            string sep1 = DatabaseEditUtil.SepBegin(cnt.NameDelimiterStyle);
            string sep2 = DatabaseEditUtil.SepEnd(cnt.NameDelimiterStyle);

            db.SetCommandText("SELECT * FROM " + sep1 + ViewName + sep2);
            db.SetCommandType(System.Data.CommandType.Text);
            try
            {
                db.OpenReader(System.Data.CommandBehavior.SchemaOnly);
                schemaColumn = db.GetSchemaTable();
                db.CloseReader();
                db.Close();
                if (schemaColumn != null)
                {
                    for (i = 0; i < schemaColumn.Rows.Count; i++)
                    {
                        fld = EPField.MakeFieldFromColumnInfo(i, schemaColumn.Rows[i]);
                        fld.FromTableName = ViewName;
                        fields.AddField(fld);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                db.CloseReader();
                db.Close();
            }
        }