Link to home
Start Free TrialLog in
Avatar of jonastovsen
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.StoredProcedure
        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"
Avatar of Praveen Kumar
Praveen Kumar
Flag of India image

It is good to change your Stored Procedure and send one extra column, which is cancatinated all values.
SQL Looks like:

Select Name, Phone, Address, Name + Phone + Address As 'All' From Table
ASKER CERTIFIED SOLUTION
Avatar of newyuppie
newyuppie
Flag of Ecuador image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZeonFlash
ZeonFlash

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
Avatar of jonastovsen

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.