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

3
Contributors
6
Replies
10
Views
7 Years
Discussion Span
Last Post by lonelyrider
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;
...
..
 ....
0

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

0

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

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.