Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.net 2010 using code to fill combobox

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have this code to fill a DataGridView but when using it to fill a combo box it fills it with 4 lines of System.Data.DataRowView.
There are 4 rows in the table but its not putting in the columns data I passed in the SQL String.
Can some one help me fill a combo box with "Category" from the table?
Code:
    Public Function PopulateGridwithSQL(SQLStatement As String)
        'this function takes a SQL string, open the SQL server
        '  returns a datatable which can populates grid directly
        Dim Conn As SqlConnection
        Conn = New SqlConnection(gblconnectionString)
        Conn.Open()
        Dim daTrans As New SqlDataAdapter
        Dim dtTrans As New DataTable
        daTrans.SelectCommand = New SqlCommand(SQLStatement, Conn)
        daTrans.Fill(dtTrans)
        Return dtTrans
        Conn = Nothing
    End Function
'-------------------- I call it like so ---------
        'fill grid works great
        Dim SQLString As String
        SQLString = "Select DonorName from AuctionDonors Where Donorname <> ''"
        Me.DataGridView1.DataSource = PopulateGridwithSQL(SQLString)
        'fill Donor combobox does not work; returns 4 rows of  System.Data.DataRowView
        SQLString = "Select Category from AuctionCategories"
        Me.cboCategory.DataSource = PopulateGridwithSQL(SQLString)

DougP
 
I use something like:

With ComboBox1
.DataSource = DS.Tables("Table")
.DisplayMember = "LocationName"
.ValueMember = "LocationNum"
.SelectedIndex = 0
End With

To fill the combo box
 

I've found that I get this error when I set the DataSource property before the DisplayMember of ValueMember properties. Try setting the DataMember after the DisplayMember and ValueMember.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top