/// <summary>
        /// 这是一个缓存表结构的部分,避免每一次新建对象需要去查询数据库获取其结构
        /// </summary>
        ///static Dictionary<string, DataRow> lstTable = new Dictionary<string, DataRow>();
        /// <summary>
        ///  获取一个新行作为新建对象的数据容器
        /// </summary>
        /// <param name="tablename">数据表明</param>
        /// <returns></returns>
        static DataRow GetNewDataRow(string tablename)
        {
            ///这里采用查询语句获取一行来作为数据库容器,因为包装类需要datatable的列信息,包括字段名称和类型等
            DataRow row = null;

            //lstTable.TryGetValue(tablename, out row);

            if (row == null)
            {
                DataTable dt;
                if (DbHelper.DBType == DatabaseType.Oracle)
                {
                    dt = DbHelper.GetDataTable("select * from " + tablename + " where rownum=1");
                }
                else if (DbHelper.DBType == DatabaseType.MsSql)
                {
                    dt = DbHelper.GetDataTable("select top 1 * from " + tablename + "");
                }
                else
                {
                    dt = DbHelper.GetDataTable("select top 1 * from " + tablename + "");
                }
                row = dt.NewRow();
            }
            return(row.Table.NewRow());
        }
Esempio n. 2
0
        public QcNewNode(string tablename, string code, string codefield)
            : base(null, tablename, code)
        {
            string sql = "";

            if (code.IndexOf(';') > 0)
            {
                sql = GetMutiSql(tablename, code, codefield);
            }
            else
            {
                sql = "select * from " + tablename + " where " + codefield + "='" + code + "'";
            }
            var dt   = DbHelper.GetDataTable(sql);
            var rows = dt.Rows;

            if (rows != null)
            {
                if (rows.Count > 0)
                {
                    this.row = rows[0];
                }
                if (this.row == null)
                {
                    this.row = dt.NewRow();
                }
            }
            this.codefield = codefield;
            this.code      = code;
        }