Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

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.
Avatar of BToson
BToson
Flag of United Kingdom of Great Britain and Northern Ireland image

A LINQ query suckh as this should work:
SELECT M FROM db.sMenu ORDER BY M.MenuName
Avatar of Starr Duskk

ASKER

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.
 
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

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.
 
SOLUTION
Avatar of BToson
BToson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
 
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!
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.
 
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...
As stated above.
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.
 
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.
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.
 
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
 
modus_operandi - FYI I did not receive notification of the points nor does it actually matter.  Nevermind.
Onwards and upwards....