关闭

OleDbSchemaGuid的应用

标签: tablesql serverobjectschema数据库join
2089人阅读 评论(0) 收藏 举报
分类:

   string ConStr;
   ConStr = "Provider=SQLOLEDB;data source=127.0.0.1;uid=sa;pwd=;database=KWDataBase";
   DataTable STable;
   DataTable SDTable;
   DataTable SFTypeTable;
   OleDbConnection OleDbCon = new OleDbConnection();
   OleDbCon.ConnectionString = ConStr;   
   OleDbCon.Open();
   OleDbCommand OleDbCmd = new OleDbCommand(Sql,OleDbCon);
   //Object[]{"TABLE_CATALOG","TABLE_SCHEMA","TABLE_NAME","TABLE_TYPE"}
   STable = OleDbCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new Object[]{"KWDataBase","dbo","member",null}); 
   //Object[]{"TABLE_CATALOG","TABLE_SCHEMA","TABLE_NAME","COLUMN_NAME"}
   SDTable = OleDbCon.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,new Object[]{"KWDataBase","dbo","member",null});
   SFTypeTable = OleDbCon.GetOleDbSchemaTable(OleDbSchemaGuid.Provider_Types,new Object[]{}); 
   this.DataGrid1.DataSource = STable;
   this.DataGrid1.DataBind();
   this.DataGrid2.DataSource = SDTable;
   this.DataGrid2.DataBind();
   this.DataGrid3.DataSource = SFTypeTable;
   this.DataGrid3.DataBind();
   OleDbCon.Close();
Sql Server 取数据库结构不用向以上方法哪样麻烦,只用一条 SQL 语句就可以了

"select c.Name,b.name,a.* from dbo.syscolumns a
inner join dbo.sysobjects b on a.ID=b.ID
inner join dbo.systypes c on a.XTYPE=c.XTYPE
where b.xtype='U'"

但如果取 Access 数据库表结构也只能用OleDbSchemaGuid了

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:169016次
    • 积分:2997
    • 等级:
    • 排名:第12155名
    • 原创:126篇
    • 转载:3篇
    • 译文:0篇
    • 评论:28条
    文章分类
    最新评论