Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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();
                }

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
Posted
Updated 4-Sep-11 2:24am
v2

Have a look at this[^] OleDbSchemaTable sample. You should be able to use it to get all the details you are looking for.
 
Share this answer
 
Comments
amitk_189 4-Sep-11 9:01am    
Got it.
thanks but the answer was in VB.net, with the logic provided in got result in C#.net
Abhinav S 4-Sep-11 9:42am    
It should not be too difficult to convert into C#.
You can always use a a tool to do so otherwise.
meerDcoder 28-Sep-20 4:20am    
This link is no more there. Please update thanks
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.

C#
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(" || ");
}
 
Share this answer
 
v2
Comments
meerDcoder 28-Sep-20 4:20am    
This gives me the names of the columns of the Schema and not the required table. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900