Im trying to get the column names from a database and display them in textboxes. someone has already helped me by tellnig me that i need to use the FillSchema command. Which works just fine and I can see only the colum names in a datagrid when i bind it to that.
The problem is that I do not know how to extract the name of a column and put it in to a textbox ?
does anybody know how I can fo this ?
Thanks a million
RobExamples
This example returns column information for a specified table.
EXEC sp_columns @.table_name = 'customers'
sp_columns
Returns column information for the specified tables or views that can be queried in the current environment.
Syntax
sp_columns [ @.table_name = ] object
[ , [ @.table_owner = ] owner ]
[ , [ @.table_qualifier = ] qualifier ]
[ , [ @.column_name = ] column ]
[ , [ @.ODBCVer = ] ODBCVer ]
Arguments
[@.table_name =] object
Is the name of the table or view used to return catalog information. object_name is nvarchar(384), with no default. Wildcard pattern matching is not supported.
[@.table_owner =] owner
Is the object owner of the table or view used to return catalog information. owner is nvarchar(384), with a default of NULL. Wildcard pattern matching is not supported. If owner is not specified, the default table or view visibility rules of the underlying DBMS apply.
In Microsoft® SQL Server?, if the current user owns a table or view with the specified name, that table's columns are returned. If owner is not specified and the current user does not own a table or view with the specified object, sp_columns looks for a table or view with the specified object owned by the database owner. If one exists, that table's columns are returned.
[@.table_qualifier =] qualifier
Is the name of the table or view qualifier. qualifier is sysname, with a default of NULL. Various DBMS products support three-part naming for tables (qualifier.owner.name). In SQL Server, this column represents the database name. In some products, it represents the server name of the table's database environment.
[@.column_name =] column
Is a single column and is used when only one column of catalog information is wanted. column is nvarchar(384), with a default of NULL. If column is not specified, all columns are returned. In SQL Server, column represents the column name as listed in the syscolumns table. column can include wildcard characters using the underlying DBMS's wildcard matching patterns. For maximum interoperability, the gateway client should assume only SQL-92 standard pattern matching (the % and _ wildcard characters).
[@.ODBCVer =] ODBCVer
Is the version of ODBC being used. ODBCVer is int, with a default of 2, indicating ODBC Version 2. Valid values are 2 or 3. Refer to the ODBC SQLColumns specification for the behavior differences between versions 2 and 3.
Return Code Values
None
Result Sets
The sp_columns catalog stored procedure is equivalent to SQLColumns in ODBC. The results returned are ordered by TABLE_QUALIFIER, TABLE_OWNER, and TABLE_NAME.|||Assuming you've fill schema'd a dataSet with a table called "MyColumns" you can access the column names using the Columns collection for the datatable.
// C#
// the first column will be at index 0, the second at index 1, and so on up to dataSet.Tables["MyColumns"].Columns.Count - 1
MyTextBox0.Text = dataSet.Tables["MyColumns"].Columns[0].ColumnName
Not sure how your page is structured but you'll probably need some way to dynamically handle the number of columns returned so you can provide one textbox for each column.|||Thanks very much, both of you
It has solved my problem :)
Beers on me !!!
No comments:
Post a Comment