-
June 3rd, 2002, 03:38 PM
#1
ComboBox.DataSource?
I'm querying a db and I want to load in data into a ComboBox. Has anyone played around with this? It has to be real easy and similiar to throwing data into a DataGrid? My code is below.....
MY CODE:
Code:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsV As DataSet
dsV = LoadVendors()
cboVendors.DataSource = dsV.Tables("VENDORS")
End Sub
Public Function LoadVendors() As DataSet
Dim cnNODsql As New SqlConnection("server=serv;database=NOLCsql;uid=sa;pwd=;")
Dim cmdSelect As New SqlCommand()
Dim daVendors As New SqlDataAdapter()
Dim dsVendors As New DataSet()
Try
With cmdSelect
.CommandText = "spLoadVendors" '"spSELECTUnassignedOrders" SearchTitlesByAuthorLastName"
.CommandType = System.Data.CommandType.StoredProcedure
.Connection = cnNODsql
End With
With daVendors
.SelectCommand = cmdSelect
.Fill(dsVendors, "VENDORS")
End With
LoadVendors = dsVendors
Catch excSQL As SqlException
' Add exception handling
End Try
End Function
thanks again.....
-
June 4th, 2002, 07:00 AM
#2
Dim cnNorthwind As New SqlConnection("Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind")
Dim cmCustomers As New SqlCommand("uspS_Company", cnNorthwind)
Dim daCustomers As New SqlDataAdapter(cmCustomers)
Dim dsCustomers As New DataSet()
Dim drCustomers As DataRow
'fill DataSet
daCustomers.Fill(dsCustomers, "Customers")
'adding items with DataRow from DataSet
For Each drCustomers In dsCustomers.Tables("Customers").Rows
cbo.Items.Add(drCustomers("CompanyName"))
Next
Enjoy.
-
June 4th, 2002, 07:29 AM
#3
cboVendors.DataSource = dsV.Tables("VENDORS")
cboVendors.DisplayMember= dsV.Tables("VENDORS").Columns("WhateverYouWantToDisplay").Caption
-
June 4th, 2002, 08:02 AM
#4
UNBELIEVABLE! THANKS........
-
June 4th, 2002, 08:14 AM
#5
Anytime
-
September 21st, 2004, 09:16 AM
#6
Re: ComboBox.DataSource?
Akim is correct, but do not use the 'Caption', instead use the 'ColumnName'.
The 'Caption' is language specific, and may differ from the actual 'ColumnName' in your table on a localized Form.
Also the 'Caption' may not be unique (at least is does not have to be) in your table, at which point the ComboBox will only ever display the first instance.
-
March 11th, 2012, 04:23 AM
#7
Re: ComboBox.DataSource?
Hi ,
could u please give me the correct code.
I have made as
ComboBox1.DisplayMember = dsSeg.Tables("dsTBL").Columns("country_id").ColumnName
where dstbl is table name.
country_id is the column name..
i get error as object reference set to null
Please help
thanks in advance
-
March 11th, 2012, 04:45 AM
#8
Re: ComboBox.DataSource?
to be clear of the doubt i ask
I dont know how to call the combo box to fill up after getting the dataset assignment from loadvendors()
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsV As DataSet
dsV = LoadVendors()
???
???
could u please explain how to do,and please give me explaination for both the lines of
combobox.datasource
combobox.displaymember
this may be silly thing,but it s confusing me alot
thanks in advance.
waitin for ur sooner reply
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
|