Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have this, no error but it doesn't work

C#
POSDataContext pos = new POSDataContext();
Credential c = new Credential();

var q = from m in pos.Credentials where c.UserName == usernamelabel.Text select m;

fnamelabel.Text = c.FirstName;
lnamelabel.Text = c.LastName;
pnumberlabel.Text = c.PhoneNumber;
dateofcreationlabel.Text = c.DateCreated.ToString();
privilegelabel.Text = c.Privilege;
Posted
Updated 20-Nov-15 10:00am
v3
Comments
Afzaal Ahmad Zeeshan 20-Nov-15 15:25pm    
"doesn't work" — why?

There are many possible reasons for this claim of yours. How do you want it to work and how does it not work?
Member 11673987 20-Nov-15 15:44pm    
i want the values coming from the database to enter the listed controls. though no error but it doesn't work... help me please

1 solution

Take a look at your Linq query:
C#
var q = from m in pos.Credentials where c.UserName == usernamelabel.Text select m;

What c is doing there?

I guess that q returns a IEnumerable<Credential>. So, you have to loop through the collection of Credential to be able to use its properties:
C#
foreach(Credential c in q)
{
   Console.WriteLine("{0}", c.FirstName);
}


But... if you would like to return single object, try this:
C#
var q = pos.Credentials.Where(c=>c.UserName == "User1").SingleOrDefault();

then:
C#
fnamelabel.Text = q.FirstName
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900