OleDbSchemaGuid.Columns返回DataTable介绍

  DataTable columnTable = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null });

一直想找一下这里面返回的DataTable的列名,可是到现在还没找到,到是在http://www.cnblogs.com/CPFlying/archive/2010/11/13/1876510.html中找到一段有用的东西;

     foreach (DataRow dr2 in columnTable.Rows)
     {
      FieldInfo fi = new FieldInfo();
      fi.DataType = dr2["DATA_TYPE"].ToString();
      fi.IsNull = Convert.ToInt16(dr2["IS_NULLABLE"]);
      fi.IsHasDefault = Convert.ToInt16(dr2["COLUMN_HASDEFAULT"]) ;
      fi.DefaultVal = dr2["COLUMN_DEFAULT"].ToString() ;
      fi.Length = dr2["CHARACTER_MAXIMUM_LENGTH"].ToString();

         htTb.Add(dr2["COLUMN_NAME"],fi);
     }

想到了,这段代码就能实现:

schemaTable 是一个OleDbSchemaGuid.Columns返回的DataTable;    

            for (int i = 0; i < schemaTable.Columns.Count; i++)
                {
                    Msg += i.ToString()+":"+schemaTable.Columns[i].ColumnName+"<br/>";
                }

打印结果

0:TABLE_CATALOG
1:TABLE_SCHEMA
2:TABLE_NAME
3:COLUMN_NAME
4:COLUMN_GUID
5:COLUMN_PROPID
6:ORDINAL_POSITION
7:COLUMN_HASDEFAULT
8:COLUMN_DEFAULT
9:COLUMN_FLAGS
10:IS_NULLABLE
11:DATA_TYPE
12:TYPE_GUID
13:CHARACTER_MAXIMUM_LENGTH
14:CHARACTER_OCTET_LENGTH
15:NUMERIC_PRECISION
16:NUMERIC_SCALE
17:DATETIME_PRECISION
18:CHARACTER_SET_CATALOG
19:CHARACTER_SET_SCHEMA
20:CHARACTER_SET_NAME
21:COLLATION_CATALOG
22:COLLATION_SCHEMA
23:COLLATION_NAME
24:DOMAIN_CATALOG
25:DOMAIN_SCHEMA
26:DOMAIN_NAME
27:DESCRIPTION
其中:对每行tDr 进行tDr["DATA_TYPE"].ToString()获取,获取的值为130、3、7这样的数值;

DataType枚举就有作用了,这里保存一个地址:http://technet.microsoft.com/zh-cn/magazine/microsoft.sqlserver.dts.runtime.wrapper.datatype(SQL.105).aspx 或搜索 DataType枚举

posted @ 2013-01-17 11:11  xyzyyj  阅读(1741)  评论(0编辑  收藏  举报