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