获取访问表列名和数据类型 [英] Get access table Column name and Datatype

查看:77
本文介绍了获取访问表列名和数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OleDbConnection cn = new ("Provider=Microsoft.ACE.OLEDB.12.0;Data=C:\\Documents and Settings\\User\\My Documents\\Database1.accdb");
                cn.Open();
                
DataTable schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });
                //List the table name from each row in the schema table.
                for (int i = 0; i < schemaTable.Rows.Count; i++)
                {
                    string Current_Str = schemaTable.Rows[i].ItemArray[2].ToString();
                }


使用上面的代码,我了解了如何在Access数据库中获得表名.
但是如何提取单个表的列名和数据类型


任何建议


using the above code i some how got the Table Names in access database.
But how can i extract the individual table''s Column Name and Datatypes


Any Suggestions

推荐答案

看看 [ ^ ] OleDbSchemaTable 示例.您应该可以使用它来获取所需的所有详细信息.
Have a look at this[^] OleDbSchemaTable sample. You should be able to use it to get all the details you are looking for.


请尝试以下代码.它将为您提供所有属于您的DataTable-"schemaTable"的列名及其数据类型.然后以您想要的方式使用它.

Try as below code. It will give you all the Column Names and their DataTypes belonging to your DataTable - "schemaTable". Then use it in the way you want.

StringBuilder sbColumnDetails = new StringBuilder();
foreach (DataColumn column in schemaTable.Columns)
{
  sbColumnDetails.Append("Column Name: ");
  sbColumnDetails.Append(column.ColumnName);

  sbColumnDetails.Append(" ");

  sbColumnDetails.Append("Column DataType: ");
  sbColumnDetails.Append(column.DataType.ToString());

 sbColumnDetails.Append(" || ");
}


这篇关于获取访问表列名和数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆