Solved

Fill a combobox from a Stored Procedure

Posted on 2006-11-08
5
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Expert Comment

by:Praveen Kumar
ID: 17898542
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
ID: 17898679
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
ID: 17898743
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
ID: 17905640
..or use a datagrid control
0
 

Author Comment

by:jonastovsen
ID: 17913334

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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