Exemple #1
0
        public AjaxResult getColumns(string table, string db = "", string uid = "", string pwd = "", string ds = "")
        {
            string _connectionString = string.Format(@"Data Source={0};Initial Catalog={3};Persist Security Info=True;User ID={1};Password={2};Pooling=true;Min Pool Size=1;Max Pool Size=500;MultipleActiveResultSets=true"
                                                     , string.IsNullOrEmpty(ds) ? "" : ds
                                                     , string.IsNullOrEmpty(uid) ? "" : uid
                                                     , string.IsNullOrEmpty(pwd) ? "" : pwd
                                                     , string.IsNullOrEmpty(db) ? "" : db
                                                     );
            SqlServerDAL dal = string.IsNullOrEmpty(ds) ? new SqlServerDAL() : new SqlServerDAL(_connectionString);
            string       sql = string.Format(@"
select obj.name table_name,col.name column_name
,t.name data_type,col.length data_length,col.isnullable,ep.[value] column_description
,isnull(pkIndex.is_primary_key,cast(0 as bit)) is_primary_key
from syscolumns col
inner join sysobjects obj on col.id = obj.id AND obj.xtype = 'U' AND obj.status >= 0  
left join systypes t on col.xusertype = t.xusertype 
left join sys.extended_properties ep on  col.id = ep.major_id AND col.colid = ep.minor_id AND ep.name = 'MS_Description' 
left join sys.index_columns colIndex on colIndex.object_id=col.id and colIndex.column_id=col.colid
left join sys.indexes pkIndex on pkIndex.object_id = colIndex.object_id and pkIndex.index_id = colIndex.index_id
where obj.name='{0}'
", string.IsNullOrEmpty(table) ? "" : table);

            return(new AjaxResult
            {
                statusCode = 200,
                data = dal.ExecuteDataTable(sql, null, CommandType.Text)
            });
        }
Exemple #2
0
        public AjaxResult getDatabase(string uid = "", string pwd = "", string ds = "")
        {
            string _connectionString = string.Format(@"Data Source={0};Initial Catalog=master;Persist Security Info=True;User ID={1};Password={2};Pooling=true;Min Pool Size=1;Max Pool Size=500;MultipleActiveResultSets=true"
                                                     , string.IsNullOrEmpty(ds) ? "" : ds
                                                     , string.IsNullOrEmpty(uid) ? "" : uid
                                                     , string.IsNullOrEmpty(pwd) ? "" : pwd
                                                     );
            SqlServerDAL dal = string.IsNullOrEmpty(ds) ? new SqlServerDAL(): new SqlServerDAL(_connectionString);

            return(new AjaxResult
            {
                statusCode = 200,
                data = dal.ExecuteDataTable("SELECT name,filename FROM SYSDATABASES ORDER BY name", null, CommandType.Text)
            });
        }
Exemple #3
0
        public AjaxResult getTable(string db = "", string uid = "", string pwd = "", string ds = "")
        {
            string _connectionString = string.Format(@"Data Source={0};Initial Catalog={3};Persist Security Info=True;User ID={1};Password={2};Pooling=true;Min Pool Size=1;Max Pool Size=500;MultipleActiveResultSets=true"
                                                     , string.IsNullOrEmpty(ds) ? "" : ds
                                                     , string.IsNullOrEmpty(uid) ? "" : uid
                                                     , string.IsNullOrEmpty(pwd) ? "" : pwd
                                                     , string.IsNullOrEmpty(db) ? "" : db
                                                     );
            SqlServerDAL dal = string.IsNullOrEmpty(ds) ? new SqlServerDAL() : new SqlServerDAL(_connectionString);

            return(new AjaxResult
            {
                statusCode = 200,
                data = dal.ExecuteDataTable("select name,crdate from dbo.sysobjects where xtype='U ' AND [status] >= 0", null, CommandType.Text)
            });
        }