Retrieving table column

  • Thread starter Thread starter Ian
  • Start date Start date
for each col as datacolumn in table.columns
col.columnname
next
How do I retrieve a list of column names in a table using the OleDbDataAdapter?

Ian
 
I assume I need to create a dataset to do this. Is there anyway of using SQL just to return the column names without any data?

Ian
for each col as datacolumn in table.columns
col.columnname
next
How do I retrieve a list of column names in a table using the OleDbDataAdapter?

Ian
 
Try this SQL: select Name from syscolumns where id=Object_id('TableName')

--
----------Ñ©ÔÆÓ¥
¾´ÉÏ--------------

MSN:[email protected]
ÐÅÄî:·ÖÏí֪ʶ¡¢¹²
´´¼¤Çé¡¢¹²Í¬³É¾Í

Blog:http://shanquan.blogone.net
-----------------
-----------------

"Ian" <[email protected]> дÈëÓʼþ
How do I retrieve a list of column names in a table using the
OleDbDataAdapter?

Ian
 
Hi Ian,

Try this:
oleDbConnection1.Open();

DataTable schemaTable =
oleDbConnection1.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,

new object[] {null, null, "YourTableName"});

oleDbConnection1.Close();

All the data is stored into schemaTable.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

How do I retrieve a list of column names in a table using the
OleDbDataAdapter?

Ian
 
¤ How do I retrieve a list of column names in a table using the OleDbDataAdapter?

You didn't identify the type of database you are using but I've posted an example using VB.NET:

Sub ListTableSchema()

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\My Documents\db1.mdb"

DatabaseConnection.Open()

'Retrieve schema information about Table1 Columns.
SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

Dim RowCount As Int32
For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!COLUMN_NAME.ToString)
Next RowCount

DataGrid1.DataSource = SchemaTable

DatabaseConnection.Close()

End Sub


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top