.aspx
Untitled Page
.aspx.cs
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ltlBody.Text = GetTableStr("FubonConnectionString"); } } string GetTableStr(string conStr) { DataBase db = null; if (string.IsNullOrEmpty(conStr)) db = new DataBase(); else db = new DataBase(conStr); string sql = @"select TableName = O.name, OWNER = USER_NAME(O.uid), FieldId = C.colid, FieldName = C.name, FieldType = T.name + CASE WHEN T.name IN (N'decimal',N'numeric') THEN N'(' + CAST(C.prec as varchar) + N',' + CAST(C.scale as varchar) + N')' WHEN T.name = N'float' OR T.name like N'%char' OR T.name like N'%binary' THEN N'(' + CAST(C.prec as varchar) + N')' ELSE N'' END, AllowNulls = CASE WHEN C.isnullable = 1 THEN N'' ELSE N' NOT' END + N' NULL', FieldDescription = ISNULL(PFD.value, ''), DefileLength = C.length, FiledDefault = ISNULL(DF.text, N''), IsIDENTITY = COLUMNPROPERTY(O.id, C.name, N'IsIdentity'), IsComputed = COLUMNPROPERTY(O.id, C.name, N'IsComputed'), IsROWGUID = COLUMNPROPERTY(O.id, C.name, N'IsRowGuidCol'), IsPrimaryKey = CASE WHEN OPK.xtype IS NULL THEN 0 ELSE 1 END FROM sysobjects O JOIN syscolumns C ON C.id = O.id AND OBJECTPROPERTY(O.id, N'IsUserTable') = 1 JOIN systypes T ON T.xusertype = C.xusertype LEFT JOIN syscomments DF ON DF.id = C.cdefault LEFT JOIN sys.extended_properties PFD ON PFD.major_id = C.id AND PFD.minor_id = C.colid LEFT JOIN sysindexkeys IDXK ON IDXK.id = O.id AND IDXK.colid = C.colid LEFT JOIN sysindexes IDX ON IDX.indid = IDXK.indid AND IDX.id =IDXK.id AND IDX.indid NOT IN(0,255) LEFT JOIN sysobjects OPK ON OPK.parent_obj = O.id AND OPK.name = IDX.name AND OBJECTPROPERTY(OPK.id, N'IsPrimaryKey') = 1ORDER BY O.name, C.colid"; DataTable dt = db.GetDataSet(sql).Tables[0]; if (dt == null || dt.Rows.Count == 0) return ""; string tableName = dt.Rows[0]["TableName"].ToString(); const string tableStr = "
TableName | "; const string columnStr = " | ||||||
Id | ColumnName | DataType | DefaultValue | IsPrimaryKey | IsIdentity | AllowNulls | Description |
{0} |
({1}) |