Solved

LINQ using PROCs... aps.net c#

Posted on 2014-11-18
10
113 Views
Last Modified: 2016-02-15
I am getting error with the following code:
           ListBox1.Items.Clear();
           var ps2 = wscgsContext.spGetData("John");
           foreach (spGetDataResult s2 in ps2)
           {
               ListBox1.Items.Add(s2.City);
           }
           

Open in new window


Question: How can I correct this?

LINQ below works fine (FYI, I do not run both codes at the same time):
           ListBox1.Items.Clear();
           var ps = from p in wscgsContext.Searches
                    where p.City == "New York"
                    orderby p.Last_Name
                    select p;
           foreach (Search s in ps)
           {
               ListBox1.Items.Add(s.Address);
           }

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 5
  • 3
  • 2
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40449900
What is the error?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40449912
Sorry,

Data doesn't show up in ListBox1 when running spGetData("John");

But with wscgsContext.Searches it data shows up in ListBox1.

When I step through, it doesn't go inside "foreach (spGetDataResult s2 in ps2)" loop.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40449918
You state the following, "I am getting error with the following code:", what is the exact error message.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40449924
Hi Fernando,

I didn't have my Coffee this morning, that is why I forgot to give the description of the problem. Please see my last post.

Mike
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 150 total points
ID: 40449926
it doesn't go inside "foreach (spGetDataResult s2 in ps2)" loop.
That means there's nothing in ps2 to loop over. Have you tried executing your sproc manually within SSMS?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 350 total points
ID: 40449927
If it is not going inside the foreach loop it is because the collection is empty. Are you sure that using the parameter "John" will return anything?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40449928
Yes, I have tested this proc in SSMS and it works fine.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40449931
re> "John" will return anything?

brb
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40449932
Can you post the stored procedure here please.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40449943
Fernando,

I need to get my coffee now. "John" was now a good criteria.

kaufmed,
I had tested with "Mike" in SSMS.

Thanks,

Mike
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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

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

10 Experts available now in Live!

Get 1:1 Help Now