private static SqlServerColumn[] GetColumnsOfTable_2000(string table)
 {
     const string strSql =
         "select c.name as ColumnName, ty.name as ColumnType, c.length as ColumnSize\r\n  from syscolumns as c\r\n  inner join sysobjects as t on t.id=c.id\r\n  inner join systypes as ty on ty.xtype = c.xtype\r\nwhere t.xtype='U' and t.name=@TheTable";
     IDataReader dataReader = (IDataReader) null;
     try
     {
         DbHelper dbHelper = DbFactory.CreateDatabase();
         DbCommand sqlStringCommand = dbHelper.GetSqlStringCommand(strSql);
         dbHelper.AddInParameter(sqlStringCommand, "@TheTable", DbType.AnsiString, (object) table);
         dataReader = dbHelper.ExecuteReader(sqlStringCommand);
         List<SqlServerColumn> list = new List<SqlServerColumn>(32);
         while (dataReader.Read())
         {
             SqlServerColumn sqlServerColumn = new SqlServerColumn()
             {
                 ColumnName = dataReader.GetString(0),
                 ColumnType = dataReader.GetString(1),
                 ColumnSize = int.Parse(dataReader.GetValue(2).ToString())
             };
             list.Add(sqlServerColumn);
         }
         return list.Count == 0 ? (SqlServerColumn[]) null : list.ToArray();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (dataReader != null)
             dataReader.Close();
     }
 }
Exemple #2
0
        private static SqlServerColumn[] GetColumnsOfTable_2005(string table)
        {
            const string strSql =
                "select c.name as ColumnName, ty.name as ColumnType, c.max_length as ColumnSize\r\n  from sys.columns as c\r\n  inner join sys.tables as t on t.object_id=c.object_id\r\n  inner join sys.types as ty on ty.system_type_id = c.system_type_id\r\nwhere ty.system_type_id=ty.user_type_id and t.name=@TheTable";
            IDataReader dataReader = (IDataReader)null;

            try
            {
                DbHelper  dbHelper         = DbFactory.CreateDatabase();
                DbCommand sqlStringCommand = dbHelper.GetSqlStringCommand(strSql);
                dbHelper.AddInParameter(sqlStringCommand, "@TheTable", DbType.AnsiString, (object)table);
                dataReader = dbHelper.ExecuteReader(sqlStringCommand);
                List <SqlServerColumn> list = new List <SqlServerColumn>(32);
                while (dataReader.Read())
                {
                    SqlServerColumn sqlServerColumn = new SqlServerColumn()
                    {
                        ColumnName = dataReader.GetString(0),
                        ColumnType = dataReader.GetString(1),
                        ColumnSize = int.Parse(dataReader.GetValue(2).ToString())
                    };
                    list.Add(sqlServerColumn);
                }
                return(list.Count == 0 ? (SqlServerColumn[])null : list.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
            }
        }