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 :)

Recommended Answers

All 6 Replies

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;
...
..
 ....

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.., :)

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.