Solved

LINQ using PROCs... aps.net c#

Posted on 2014-11-18
10
110 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 74

Expert Comment

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

Author Comment

by:Mike Eghtebas
Comment Utility
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
Comment Utility
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
Comment Utility
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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 150 total points
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 350 total points
Comment Utility
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
Comment Utility
Yes, I have tested this proc in SSMS and it works fine.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
re> "John" will return anything?

brb
0
 
LVL 62

Expert Comment

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

Author Comment

by:Mike Eghtebas
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

11 Experts available now in Live!

Get 1:1 Help Now