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

Top 5 Contributors of the Month

Home >> Forum >> Others >> Post New QuestionBookmark and Share Subscribe to Forum

how to write Query to retrieve column names in ms access

Posted By: Vikramraj     Posted Date: October 07, 2010    Points:2   Category :Others
i want to rerive coloumn name from tables in ms access. plz send me query for this

Author: Syed Shakeer Hussain             
Posted Date: October 07, 2010     Points: 5   


first Create a Table in MS-Access.

How to write a Code to Retrive data from a Ms-Access DataBase?
1)If you are using MS-Access DataBase you have to include the NameSpace as
using System.Data;
using System.Data.Oledb;

2)Connect a OledbConnection to the Ms-Access DataBase as follows.

OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["MS-db1ConnectionString"].ConnectionString);

(Check the Below link to set a MS-Acces Connection String in Web.Config)

3)call the OledbCommand to retrive data from a TABLE..(here my table name is student)

OledbCommand cmd = new OleDbCommand("select column1,colum2 from student", conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "student");
GridView1.DataSource = ds.Tables["student"];

Author: Syed Shakeer Hussain             
Posted Date: October 07, 2010     Points: 5   

If your are looking to get only column names from a Table use the below code

OdbcConnection cn=new OdbcConnection("your connection string");
OdbcDataAdapter adp=new OdbcDataAdapter("select * from tablename",cn);
DataTable dt=new DataTable();

// first column name
string first = dt.Columns[0].ColumnName;

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

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