Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this, no error but it doesn't work

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
Comments
Tomas Takac 20-Nov-15 3:11am    
Do you realize that c is empty and has no connection to your query whatsoever? You probably want to to populate the textboxes with data from database.

1 solution

Probably your code should be like
C#
POSDataContext pos = new POSDataContext();
var q = (from m in pos.Credentials where c.UserName == usernamelabel.Text select new Credential{
FirstName = m.FirstName,
LastName = m.LastName,
PhoneNumber = m.PhoneNumber,
DateCreated = m.DateCreated,
Privilege = m.Privilege
}).Single() ;
fnamelabel.Text = q.FirstName;
lnamelabel.Text = q.LastName;
pnumberlabel.Text = q.PhoneNumber;
dateofcreationlabel.Text = q.DateCreated.ToString();
privilegelabel.Text = q.Privilege;
 
Share this answer
 
v3
Comments
Tomas Takac 20-Nov-15 3:18am    
q will be IQueryable and does not have properties like FirstName or LastName. Please fix.
[no name] 20-Nov-15 3:31am    
Thanks ...
Tomas Takac 20-Nov-15 5:13am    
Not really what I meant. :) What you have there is still an IEnumerable<Credential> but you want just one Credential - I assume the username is unique. So What you need is to call .Single() on the query. Cheers.
[no name] 23-Nov-15 1:00am    
Thanks... Is it right now.
Member 11673987 20-Nov-15 8:25am    
I don't get it please .single() as how where will it be???

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