Solved

Combobox filled using datatable fails

Posted on 2008-10-10
2
703 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal Report for VS2013 17 71
Check if number is currency 15 31
Protecting vb6 & .Net code Obfuscation 18 94
Getting multiple values from a dataset ASP.NET(VB) 3 37
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

16 Experts available now in Live!

Get 1:1 Help Now