Solved

Fill a combobox from a Stored Procedure

Posted on 2006-11-08
5
468 Views
Last Modified: 2009-07-29
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"
0
Comment
Question by:jonastovsen
5 Comments
 
LVL 12

Expert Comment

by:Mamtha1982
Comment Utility
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
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 250 total points
Comment Utility
or create your own multi column combobox with databinding capabilitites.
luckily, this great article by Eric Moreau already explains and provides the source code on how to do this:
http://www.utmag.com/wconnect/wc.dll?9,7,10,772
0
 
LVL 17

Expert Comment

by:ZeonFlash
Comment Utility
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 :)
0
 
LVL 8

Expert Comment

by:doobdave
Comment Utility
..or use a datagrid control
0
 

Author Comment

by:jonastovsen
Comment Utility

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.

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now