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

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 8
Reputation: ashokrajendran is an unknown quantity at this point 
Solved Threads: 0
ashokrajendran's Avatar
ashokrajendran ashokrajendran is offline Offline
Newbie Poster

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

 
0
  #1
May 28th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

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

 
0
  #2
May 28th, 2009
Originally Posted by ashokrajendran View Post
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
  1. ...
  2. ...
  3. OdbcConnection cn=new OdbcConnection("your connection string");
  4. OdbcCommand cmd=new OdbcCommand("select * from tablename",cn);
  5.  
  6. cn.Open();
  7. OdbcDataReader dr;
  8. dr=cmd.ExecuteReader()
  9.  
  10. 'First column name
  11. string first=dr.GetName(0);
  12.  
  13. 'Second column name
  14. string second=dr.GetName(1);
  15. ...
  16. ...
  17. dr.Close();
  18. cn.Close();
  19. .....

Another ways is:

  1. ...
  2. ...
  3. OdbcConnection cn=new OdbcConnection("your connection string");
  4. OdbcDataAdapter adp=new OdbcDataAdapter("select * from tablename",cn);
  5. DataTable dt=new DataTable();
  6. adp.Fill(dt);
  7.  
  8. // first column name
  9. string first = dt.Columns[0].ColumnName;
  10. ...
  11. ..
  12. ....
Last edited by adatapost; May 28th, 2009 at 8:01 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: ashokrajendran is an unknown quantity at this point 
Solved Threads: 0
ashokrajendran's Avatar
ashokrajendran ashokrajendran is offline Offline
Newbie Poster

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

 
0
  #3
May 28th, 2009
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..,
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

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

 
0
  #4
May 28th, 2009
I am sorry!!!. Now, you can see I have changed.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: ashokrajendran is an unknown quantity at this point 
Solved Threads: 0
ashokrajendran's Avatar
ashokrajendran ashokrajendran is offline Offline
Newbie Poster

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

 
0
  #5
May 28th, 2009
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
Thanks.<br />
AshokRajendran
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

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

 
0
  #6
May 28th, 2009
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.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: lonelyrider is an unknown quantity at this point 
Solved Threads: 0
lonelyrider lonelyrider is offline Offline
Newbie Poster

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

 
0
  #7
May 30th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC