jonastovsen
asked on
Fill a combobox from a Stored Procedure
Hi Experts,
I have a combobox that is bound to a stored procedure. The problem is that I can only display one coulmn in the combobox.
I would like to display all the columns the stored procedure returns (4).
SP:
CREATE PROCEDURE [SelectAllSafe]
AS
SELECT *
FROM Safe
GO
VB code:
'------------------------- ----------
Dim sqlConn As New SqlClient.SqlConnection
sqlConn.ConnectionString = getConnection2()
sqlConn.Open()
Dim cmd As New SqlClient.SqlCommand
Dim DA As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
'------------------------- ----------
cmd.CommandText = "selectallsafe"
cmd.CommandType = CommandType.StoredProcedur e
cmd.Connection = sqlConn
cmb1_1.DataSource = Nothing
DA.SelectCommand = cmd
DA.Fill(ds, "Safe")
cmb1_1.DataSource = ds.Tables("Safe")
cmb1_1.ValueMember = "SafeID"
cmb1_1.DisplayMember = "SafeNavn"
I have a combobox that is bound to a stored procedure. The problem is that I can only display one coulmn in the combobox.
I would like to display all the columns the stored procedure returns (4).
SP:
CREATE PROCEDURE [SelectAllSafe]
AS
SELECT *
FROM Safe
GO
VB code:
'-------------------------
Dim sqlConn As New SqlClient.SqlConnection
sqlConn.ConnectionString = getConnection2()
sqlConn.Open()
Dim cmd As New SqlClient.SqlCommand
Dim DA As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
'-------------------------
cmd.CommandText = "selectallsafe"
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = sqlConn
cmb1_1.DataSource = Nothing
DA.SelectCommand = cmd
DA.Fill(ds, "Safe")
cmb1_1.DataSource = ds.Tables("Safe")
cmb1_1.ValueMember = "SafeID"
cmb1_1.DisplayMember = "SafeNavn"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or get a 3rd party control that has multi-column support in comboboxes (like http://www.infragistics.com). The first two posted solutions are a lot cheaper and easier though :)
..or use a datagrid control
ASKER
Hi,
Thank you for your time!
Unfortunately, none of the answers solved my problem. However, I will give the points to newyuppie for an interesting article.
SQL Looks like:
Select Name, Phone, Address, Name + Phone + Address As 'All' From Table