Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combobox filled using datatable fails

Posted on 2008-10-10
2
Medium Priority
?
727 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
[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
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

688 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