|
-
Apr 8th, 2009, 06:30 AM
#1
Thread Starter
Lively Member
[RESOLVED] How can I dispaly the names of the fields of a table
Hi, I want to display in a combobox the names of the fields of a table (table is in SQL server 2005). Any suggestions?
-
Apr 8th, 2009, 07:19 AM
#2
Re: How can I dispaly the names of the fields of a table
-
Apr 9th, 2009, 01:07 AM
#3
Thread Starter
Lively Member
Re: How can I dispaly the names of the fields of a table
Thank you for answering. It works. However, I have a small problem. I want to pass these values to a combobox. But when I am trying to do this it displays only the name of the last field.
objDataAdapter.Fill(objDataSet, "Table_1")
Dim dc As DataColumn
For Each dc In objDataSet.Tables("Table_1").Columns
ColSelection.Text = dc.ColumnName
Next
Do you know how can I fix this?
-
Apr 9th, 2009, 01:14 AM
#4
Re: How can I dispaly the names of the fields of a table
You're just overwriting the Text each time. If you want to add multiple items to the ComboBox then that's what you must do:
vb.net Code:
ColSelection.Items.Add(dc.ColumnName)
I haven't tested it but you should probably be able to bind the data too:
vb.net Code:
ColSelection.DisplayMember = "ColumnName" ColSelection.DataSource = objDataSet.Tables("Table_1").Columns
which you only need to do once, not in a loop.
That said, that's not how I'd get the names of the columns in a SQL Server table. I'd use the SqlConnection.GetSchema method.
http://www.vbforums.com/showthread.p...ight=getschema
-
Apr 9th, 2009, 01:22 AM
#5
Re: How can I dispaly the names of the fields of a table
Hang on a sec! I just realised that that thread is one of yours. Why are you asking the same question again if it was answered 2 1/2 months ago?
-
Apr 9th, 2009, 01:23 AM
#6
Thread Starter
Lively Member
Re: How can I dispaly the names of the fields of a table
Thank you for answering. I had some problems with the code that's why I asked again.
-
Apr 9th, 2009, 01:54 AM
#7
Re: How can I dispaly the names of the fields of a table
 Originally Posted by erom11
Thank you for answering. I had some problems with the code that's why I asked again.
Then, instead of asking the question like it's brand new so no-one who replies has any idea that you already have a solution, you should have either provided a link to that original thread or, even better, simply posted to that thread again, and explained what problems you were having so they could be rectified. If you don't do that then people waste their time telling you things that you already know and the issues don't actually get resolved.
So... exactly what problem(s) are you having with the original code?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|