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?
DougP
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