Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need data field name for columns from schema

Author  Topic 

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-07 : 20:32:10
I am attempting to fill a Gridview control in my C# web based program with the following commands:

string strSQL = "SELECT * FROM " + "\"" + table + "\"";
OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
da.FillSchema(ds, SchemaType.Source, table);

GridView1.DataSource = ds;
GridView1.DataBind();

This returns the proper number of records but it causes an error in my program because I don't know the name of the field that is being returned. The Gridview control requires a valid data field name in order to fill the Gridview. Does anyone know the name of the data field that contains the column names in the table from this schema?

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-07 : 20:39:49
I forgot to mention that I used the data field name COLUMN_NAME and the program said that it was an invalid data name.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-08 : 12:55:45
whats table? is it a variable that determine your table name at run time? whats the significance of two \'s?
Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-08 : 13:26:15
I am sorry that I posted a faulty code. The SQL command should read as follows:

string strSQL = "SELECT * FROM Burials";

I am attempting to populate a Gridview with bound data fields and a check box and a dropdown list. That is why I am trying to do a Fill of field names from a table into the Gridview because I don't how else to insert check boxes and dropdown lists into a Gridview.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-08 : 13:35:25
for getting field names use

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Burials'
Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-08 : 22:24:31
visakh16;
Thanks for your reply. Your suggestion worked.
Go to Top of Page
   

- Advertisement -