0

I need to check my tblProjects table, in the foreign key column "ClientID", for a value that matches the "ClientLoginID"(primary key) value in my tblClientLoginDetails table and I want to display the total amount of columns that match that value in a label.

Here is coding where I have tried to do so, but it doesn't display any info in my label. I think it might be because of it getting multiple values and not knowing what to do with it.

using (DataClassesDataContext DC = new DataClassesDataContext())
{
    int CurrentClient = CLD.UserID;

    var Count = DC.tblProjects.Where<tblProject>
                  (c => c.ClientID == CurrentClient);
                  lblTotalProjectsAmount.Content = Count;
}

Also I am not getting any errors with the code above?

Sorry if the question sounds vague, but I do not know how to ask it in another way. For any advice or answers, I would be very greatfull!

1 Answer 1

1

Seems you forget to use the Count() at the end of your linq:

 using (DataClassesDataContext DC = new DataClassesDataContext())
 {
    int CurrentClient = CLD.UserID;

    var Count = DC.tblProjects.Where<tblProject>
            (c => c.ClientID == CurrentClient).Count(); //THIS LINE

    lblTotalProjectsAmount.Content = Count;
}

Alternatively you may try something like this:

 using (DataClassesDataContext DC = new DataClassesDataContext())
 {
    int CurrentClient = CLD.UserID;

    var Count = DC.tblProjects.Count(c => c.ClientID == CurrentClient); //THIS LINE

    lblTotalProjectsAmount.Content = Count;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your effort! This got it fixed :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.