954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Get Column names of a table of MS Access (.mdb)- ODBC Connection

Hi all,

Im new to c#, please any one tell me how to get the column names of a table of ms access(.mdb). Here i used odbc connectivity to access the database, i got the list of tables in the database, but i dont know how to get the column name of a tables. Can any one give me a solution for the Query.

Thanks in Advance,
AshokRajendran :)

ashokrajendran
Newbie Poster
8 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Hi all,

Im new to c#, please any one tell me how to get the column names of a table of ms access(.mdb). Here i used odbc connectivity to access the database, i got the list of tables in the database, but i dont know how to get the column name of a tables. Can any one give me a solution for the Query.

Thanks in Advance, AshokRajendran :)

...
...
OdbcConnection cn=new OdbcConnection("your connection string");
OdbcCommand cmd=new OdbcCommand("select * from tablename",cn);

cn.Open();
OdbcDataReader dr;
dr=cmd.ExecuteReader()

'First column name
string first=dr.GetName(0);

'Second column name
string second=dr.GetName(1);
...
...
dr.Close();
cn.Close();
.....


Another ways is:

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

// first column name
string first = dt.Columns[0].ColumnName;
...
..
 ....
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Thank you very much adatapost

Can you help me in one more issues...
I'm using C#.Net...

How to access the msysobjects table of a .MDB file.. I'm Getting the error as unable to read.. Read permission Problem..

Kindly help asap.., :)

ashokrajendran
Newbie Poster
8 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

I am sorry!!!. Now, you can see I have changed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

alright adatapost...
i got the logic...
my another issue is...
How to access the msysobjects table of a .MDB file.. I'm Getting the error as unable to read.. Read permission Problem.. Access denied problem...

Thanks
AshokRajendran

ashokrajendran
Newbie Poster
8 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

hey ashok, you play a game. You said that ---
Here i used odbc connectivity to access the database, i got the list of tables in the database.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

OH great way of doing that i didnt know that too. Thats why i always used dr[0] based indexing instead of the names. Thanks for putting this question it helped me a lot.

lonelyrider
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You