Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I split a contact name in LINQ to create two new columns in a datagridview?

I had a query that worked nicely with a SQL adapter, but I'm needing it to not be that way, I need to use linq or entities(I'm using the entity framework). I have a contactname from customers, that i need to split and be able to search by last name. my sql query which i thought was wonderful:

("select o.OrderID, c.CompanyName, left(c.ContactName, CHARINDEX(' ', c.ContactName)) as Firstname,substring(c.ContactName, CHARINDEX(' ', c.ContactName)+1, len(c.ContactName)-(CHARINDEX(' ', c.ContactName)-1)) as Lastname, o.OrderDate, o.ShippedDate FROM Customers c JOIN Orders o ON c.CustomerID =o.CustomerID WHERE o.OrderID = @filter ORDER BY c.CompanyName ASC", connection);

Can't be used...I need to do this differently. Any tips? All I'm wanting is to change the contactname into two columns and be able to search by last name.

Update:

like i said, using a sqladapter causes this to work, but i'm wanting to do it not using SQL. I'm just not sure where to go with it.

1 Answer

Relevance
  • AJ
    Lv 7
    8 years ago
    Favorite Answer

    Your only alternative is to build a class and then add them to a list<class>

Still have questions? Get your answers by asking now.