?
Solved

How to get an item from a "var" variable when returned as sql string

Posted on 2009-02-10
7
Medium Priority
?
288 Views
Last Modified: 2013-12-17
I need the help from someone who has a really good idea of how to help me on this problem.
I am working with C#. I am calling a service that returns what looks like rows in a table. I need to know how to get only one value from what is returned.

Below is my C# code and I show the debugger contents the ClientClub var variable.

50 var clientClub = ClientService.GetClubs(); // This is the C# code on line 50
51  bool madeItHere=true;  // line 51

When I trace through the debugger and get to line 51 above, then I can do a quick watch or hover over the variable "clientClub". When I do,  the following information about the contents of "clientClub" are shown :
 {SELECT [t0].[ClubID] AS [ClubId], [t0].[ClubCode] AS [Code], [t0].[ClubName] AS [Name], [t0].[ClubDescription] AS [Description], [t0].[SortOrder]
FROM [dbo].[Club] AS [t0]
ORDER BY [t0].[SortOrder]

So here is my question. I need to get the String value "ClubName" which is stored in my var variable "clientClub". How can I do this? Please help.
50 var clientClub = ClientService.GetClubs(); // This is the C# code on line 50
51  bool madeItHere=true;  // line 51
--------------------------Next Line Shows Contents of clientClub in debugger-----------
 {SELECT [t0].[ClubID] AS [ClubId], [t0].[ClubCode] AS [Code], [t0].[ClubName] AS [Name], [t0].[ClubDescription] AS [Description], [t0].[SortOrder]
FROM [dbo].[Club] AS [t0]
ORDER BY [t0].[SortOrder]

Open in new window

0
Comment
Question by:brgdotnet
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 23600762
Do you know what this webservice returns ?
Is it a datarow, datatable, delimited text, ...
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 23601288
Ok, I can see that. So how do I get the data field I asked about? I am under much pressure to get this done.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 23601307
Still not answered my question ! Do you know what type the service returns ?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 53

Expert Comment

by:Dhaest
ID: 23601317
Depending of the type that's returned, you can try the following: clientClub["Name"].ToString()
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 23602724
I deeply appreciate your help Dhaest. I tried accessing the value as you suggested but I get the following error: Error 1 The name 'Name' does not exist in the current context.

I don't know what type the service returns, but I found this. Is this correct:
(new System.Linq.SystemCore_EnumerableDebugView<Client.Core.Model.Ethnicity>(clientClub)).Items[0].Description

0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 23603436
It looks like it returns a LINQ-result

I'm not sure, but you can try this:
var clientClub = ClientService.GetClubs();
foreach (var client in clientClub ) {
            Console.WriteLine("Client {0}", client.Name);
            }
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 31545014
This guy Dhaest is one sharp cookie!!!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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