Solved

Combobox filled using datatable fails

Posted on 2008-10-10
2
695 Views
Last Modified: 2012-05-05
I am trying to get a list of items to fill in a combobox.

I call a function and expect a return list.... what is wrong with my code?  
cbbae.DataSource = employeelist("sales")
 
 
 

    Public Shared Function employeelist(ByVal Dept As String)
 

        Dim cbb As ComboBox = New ComboBox

        Dim dt As DataTable = New DataTable

        Using conn As New SqlConnection(myconnectionstring)

            Using cmd As New SqlCommand("APP_GetEmployeeList", conn)

                cmd.CommandType = CommandType.StoredProcedure

                cmd.Parameters.AddWithValue("@department", Dept)
 
 

                Using da As New SqlDataAdapter(cmd)
 
 

                    da.Fill(dt)

                    With cbb

                        .DataSource = dt

                        .DisplayMember = "repcode"

                    End With
 
 

                End Using

            End Using

        End Using
 

        Return cbb.DisplayMember
 

    End Function

Open in new window

0
Comment
Question by:logoncom
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22694267
1)The first problem i can see is that there is no return type defined for the function. Functions are defined as
public shared function employeelist(dept as string) as string()
end function

2) you are calling the function agaist the datasource property but setting the datasource within the function and return the displaymember which is a string

Try with the following code.
cbbae.DataSource = employeelist("sales")

cbbae.DisplayMember = "repcode"

 

Public Shared Function employeelist(ByVal Dept As String) as DataTable

        Dim dt As DataTable = New DataTable

        Using conn As New SqlConnection(myconnectionstring)

            Using cmd As New SqlCommand("APP_GetEmployeeList", conn)

                cmd.CommandType = CommandType.StoredProcedure

                cmd.Parameters.AddWithValue("@department", Dept)

                Using da As New SqlDataAdapter(cmd)

                     da.Fill(dt)

                 End Using

            End Using

        End Using

         Return dt

     End Function

Open in new window

0
 

Author Closing Comment

by:logoncom
ID: 31505024
Thanks... that helped
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now