question

technette avatar image
technette asked

LINQ to SQL syntax

Dim editEmployee = (From c In Employee _
    Where (c.lastName = txtLastName.Text And c.firstName = txtFirstName.Text))
    Select c).Single()

I'm getting errors with this particular syntax. Trying to retrieve a single row for employee that matches first and last name.

linq-to-sql
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Scot Hauder avatar image
Scot Hauder answered

Try .Take(1) instead of .Single(). Single() expects only one row to be returned, if more than one employee has the same name it will throw an exception. Take(1) might not give you the employee you want if there are multiple so you may want to search for an employee id instead.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.