[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1058
  • Last Modified:

Linq class and populating combobox

I need two answers... how to do this with a function that calls a stored procedure and how to do it with a function that calls an ad hoc query.

I have created a linq to sql class which uses my sMenu table and a stored procedure.

I now am creating a class which will use the stored procedure and create ad hoc queries.

In my second class, I tried this, but really don't know what I'm doing.

  Public Shared Function [Select]() As IEnumerable(Of sMenu)
        Dim db As New sMenuDataContext
        Return db.s_GetAllMenus
    End Function

the s_getallmenus is a stored procedure, but it says that it is returning an integer, not an ienumerable... truthfully, I don't know what to return or what I'm doing. How would I do a function to return a recordset to be used by a combobox?

the sp is this:
ALTER PROCEDURE dbo.s_GetAllMenus
AS
BEGIN
      SET NOCOUNT ON;

            SELECT  *
            FROM     sMenu
            Order by  MenuName
            RETURN (0)  
END

then with my combobx, I'm using:

                Dim db As New Linq.sMenuDataContext

                With ddlCombobox
                    .Items.Clear()
                    .Items.Add(New RadComboBoxItem("Main", "0"))
                    .DataSource = db.s_GetAllMenus
                    .DataTextField = "MenuName"
                    .DataValueField = "MenuId"
                End With

Now, in the above, I have tried to do this with a stored procedure, poorly.

How also do I create an ad hoc query in my function class and then how do I apply that to my combobox?

thanks.
0
Starr Duskk
Asked:
Starr Duskk
  • 8
  • 8
2 Solutions
 
BTosonCommented:
A LINQ query suckh as this should work:
SELECT M FROM db.sMenu ORDER BY M.MenuName
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I asked specifcially how to create a function and call that functions results to my combobox.
I would like an answer that tells me how to do that. I don't need a sql query as an answer. I need an answer for what I asked.
 
0
 
BTosonCommented:
Like this?
Dim db As New Linq.sMenuDataContext
With ddlCombobox
.Items.Clear()
.Items.Add(New RadComboBoxItem("Main", "0"))
.DataSource = (SELECT M FROM db.sMenu ORDER BY M.MenuName).ToList
.DataTextField = "MenuName"
.DataValueField = "MenuId"
.DataBind()
End With

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
No, that doesn't work. I appreciate the responses, but please, I asked a specific question and none of your responses are answers to what I asked.
I dont want a query. I want a function in a class.
I would like to hear a response from someone who will answer the question that I asked.
Please don't respond again unless you can answer the questions I specifically asked.
thanks.
 
0
 
BTosonCommented:
Regarding the code, apologies - it was late and I have spottted the error.  This SHOULD work.
The DataSource line should read as follows:
.DataSource = (From M in db.sMenu Order By M.MenuName).ToList

Do you want a whole seperate class to fill the list box?  Or something like below?
It is hard to understand from your question what you actually want without clarification.
Dim db As New Linq.sMenuDataContext
ddlCombobox.Items.Clear()
For Each sMenu In (From M in db.sMenu Order By M.MenuName).ToList
ddlCombobox.Items.Add(New ListItem(sMenu.MenuName, sMenu.MenuID))
Next

Open in new window

0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
That didn't work either. It didn't error, but it also didn't return any values, although there are records in the table.
I want a 3-tier application. I want to keep all of my data queries in a class.
So I want to populate my controls with linq from a function.
But I need to know how to create a query programmatically within a function, how to return it and how to call it in the .datasource of the control.
I want a function that shows how to do it for a stored procedure as well as an ad hoc query.
thanks.
 
0
 
BTosonCommented:
As far as I am aware, there are issues with LINQ to SQL and stored procedures that return row data results.  LINQ sgould do the job just as well without anyway.

Can you please check whether (From M in db.sMenu Order By M.MenuName).Count is not 0.
Based on your original post, that should work!
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Listen, I'm going to close this out, because obviously it's migrated so far from the top of the list and has so many answers, no one else is even going to look at it.
But none-the-less you didn't even attempt to answer my question that was asked and it wasn't as obscure as you seem to indicate.
I am opening a new ticket and do NOT respond to it.
 
0
 
BTosonCommented:
I have answered the question as best I can based on the information you have provided.
You are unwilling to elaborate or assist someone who is tryign to help you.
Therefore, I will not answer your new question by my own choice...
0
 
BTosonCommented:
As stated above.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Oh please. I provided a specific question asking for a FUNCTION. A FUNCTION. A FUNCTION. A FUNCTION.
You got your 500 points. I don't know why you're whining. None of your stuff worked. I was generous with you.
 
0
 
BTosonCommented:
I got no points from this so I don't see your point.  I am hardly whining.
You don't seem to be able to string much of a sentence together and if you cant turn what I've given you into a function nor actually elaborate on anything else then more fool you.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Btoson,
When I closed the ticket, I awarded 500 points to you!
When you contested it, you cancelled the points.
So there ya go.
>>You don't seem to be able to string much of a sentence together
Nice. What don't you understand about the words "FUNCTION" or "STORED PROCEDURE"
It's people like you that grab at questions they don't know how to answer, just to get the points, that bring down the credibility of this site. Fortunately, there are enough others that make it still worth my subscription price.
Now leave me alone. I'm sure you have more questions to botch up.
 
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
He apparently is as bad at reading that message as he was at reading my question.
I'll close it again and award him the 500 points and hopefully we can all move on.
 
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I found the answer:
        Public Shared Function [Select]() As IEnumerable(Of sMenu)
            Dim db As New sMenuDataContext
            Return db.sMenus.OrderBy(Function(e) e.menuName)
        End Function
Then to populate my datasource, I use the namespace:
ddlCombobox.DataSource = Linq.sssMenu.Select
Or I could do it this way:
        Public Function GetAllMenus() As IEnumerable(Of sssMenu)
            Dim db As New sssMenuDataContext
            Return db.sssMenus.OrderBy(Function(e) e.menuName)
        End Function
 Dim db As New Linq.sssMenu
ddlCombobox.DataSource = db.GetAllMenus()
I still don't know how to do it with a stored procedure, but there's half the battle.
thanks me!
Me.
 
0
 
BTosonCommented:
modus_operandi - FYI I did not receive notification of the points nor does it actually matter.  Nevermind.
Onwards and upwards....
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now