實際應用中不免需要調取資料庫表字段的相關資訊,特此將**貼出,以作備用,調取的資訊: 欄位名、字段型別、字段長度、是否主鍵、說明
可以根據實際應用對**進行刪節和改進/// /// 建立sqlparameter
///
public class cp
public sqldbtype coltype
public int collength
public bool isprimary
public string description
}/// 指定表名,如果為空,則查詢所有表
/// 資料庫連線串
///
public static listtc(string specifytable, string connstr)
;p.add(item);}}
}return p;}}
//sqlserver資料庫型別轉換方法
public static sqldbtype stringtosqltype(string string)
return dbtype;
}#region 建立乙個引數
/// /// 根據表列資訊集合和表對應實體類所屬某個屬性返回乙個sql引數
///
/// 表列資訊集合
/// 屬性
/// 屬性對應值
/// 引數方向
/// 乙個sql引數,已經初始化
public static sqlparameter cpa(columninfo item, object v, parameterdirection pd)
sqlparameter sp = null;
if (item != null)
return sp;
}/// /// 根據表列資訊集合和表對應實體類所屬某個屬性返回乙個sql引數
///
/// 表列資訊集合
/// 屬性
/// 屬性對應值
/// 乙個sql引數,已經初始化
public static sqlparameter cpa(columninfo item, object v)
sqlparameter sp = null;
if (item != null)
return sp;
}#endregion
}
根據系統表查詢使用者表字段資訊
在sql server中查詢字段資訊的語句 select a.name as tablename,b.name as columnname,case when h.id is not null then pk else no end as primarykey,type name b.xuserty...
Mssql 根據表名查詢所有字段資訊
select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...
根據表名和模板GGUID,得到表字段 及清單資訊
if object id sp gettablecolinfo p is not null drop proc sp gettablecolinfo go create proc sp gettablecolinfo tablename varchar 128 gguid uniqueidentif...