Get table column names in combo box
The correct way to do this on SQL Server 2005 and up (you haven't specified clearly enough which version you are using) would be checking the system catalog views that live in the schema sys
:
SELECT
name
FROM
sys.columns
WHERE
object_id = object_id('YourTableNameHere')
ORDER BY
name
The catalog view sys.columns
contains fairly detailed information about the columns of a table - the table is identified by a column object_id
that is the internal identifier for the given table.
a source to share
This is how you can query the column names from sql server. Other databases are like this. http://blog.sqlauthority.com/2008/08/05/sql-server-2005-get-field-name-and-type-of-database-table/
Regarding getting items in a combobox, you can find volumes of information about it on msdn at this link http://msdn.microsoft.com/en-us/library/aa983551(VS.71).aspx
Enjoy!
a source to share
You can use this code
string sqlquery="select column_name FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'student' ORDER BY ORDINAL_POSITION";
DataFind.Open();
cmd = new SqlCommand(sqlquery, DataFind);
SqlDataReader DR = cmd.ExecuteReader();
while (DR.Read())
{
comboBox1.Items.Add(DR[0]);
}
DataFind.Close();
a source to share