.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to get table schema from ms access

Posted By: Vikramraj     Posted Date: October 19, 2010    Points:2   Category :C#
i have database having many tables in ms access.
i need code to get schema or structure of that table.

Responses
Author: Dhiraj Ranka             
Posted Date: October 20, 2010     Points: 5   

Hi,

Try out this code

OleDbConnection conn = 
new OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
"C:\\database.mdb;Persist Security Info=False;");

// retrieving schema for a single table
OleDbCommand cmd = new OleDbCommand("tablename", conn);
cmd.CommandType = CommandType.TableDirect;
conn.Open();
OleDbDataReader reader =
cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schemaTable = reader.GetSchemaTable();
reader.Close();
conn.Close();

LogFile.WriteLine(" ");
foreach (DataRow r in schemaTable.Rows)
{
LogFile.WriteLine(" ");
foreach (DataColumn c in schemaTable.Columns)
{
LogFile.WriteLine(c.ColumnName + ": " + r[c.ColumnName]);
}
}
MessageBox.Show("done");


Hope this helps

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend