EDN Admin
Well-known member
After I parse out a company name and contact name from an excel spreadsheet 2010, I need to query a sql server 2008 r2 database, to obtain more information that is needed for processing. My problem is the name and/or contact name that is obtain from
the file name, may be different than the actual value in the database.
For example the company name obtained from the file name may look like:<br/>
Blue group however the actual file company name in the database may be <br/>
Blue (of northeast) group or Blue inc?
Thus my solution is:
1. I am using the first word of the company name (or the first and second words if the first word is The) to search for the company in the database.
2.I am assuming the contact name will be something like George Washington or Ulysses S Grant, Id just search for the last word (i.e. the surname) in the database.
I have obtained the information I am looking for using the following logic:
<br/>
string company = companyName.TrimStart().Split( )[0].ToLower();<br/>
if (company == the) company += " " + companyName.Split( )[1].ToLower();<br/>
string[] items = contactName.TrimEnd().Split( );<br/>
string surname = items[items.Length - 1].ToLower();
I have tried the following 2 linqs queries but I am getting errors:
1. var query = from row in tableContext where row.CompanyName.TrimStart().ToLower().StartsWith(company) && row.ContactName.TrimEnd().ToLower().EndsWith(surname) select row;
2. var query = from row in tableContext where SqlMethods.Like(row.CompanyName.TrimStart().ToLower(), company + "%") && SqlMethods.Like(row.ContactName.TrimEnd().ToLower(), "%" + surname) select row;
Thus can you tell me show me some code on what you would change here in the linq to sql code?
View the full article
the file name, may be different than the actual value in the database.
For example the company name obtained from the file name may look like:<br/>
Blue group however the actual file company name in the database may be <br/>
Blue (of northeast) group or Blue inc?
Thus my solution is:
1. I am using the first word of the company name (or the first and second words if the first word is The) to search for the company in the database.
2.I am assuming the contact name will be something like George Washington or Ulysses S Grant, Id just search for the last word (i.e. the surname) in the database.
I have obtained the information I am looking for using the following logic:
<br/>
string company = companyName.TrimStart().Split( )[0].ToLower();<br/>
if (company == the) company += " " + companyName.Split( )[1].ToLower();<br/>
string[] items = contactName.TrimEnd().Split( );<br/>
string surname = items[items.Length - 1].ToLower();
I have tried the following 2 linqs queries but I am getting errors:
1. var query = from row in tableContext where row.CompanyName.TrimStart().ToLower().StartsWith(company) && row.ContactName.TrimEnd().ToLower().EndsWith(surname) select row;
2. var query = from row in tableContext where SqlMethods.Like(row.CompanyName.TrimStart().ToLower(), company + "%") && SqlMethods.Like(row.ContactName.TrimEnd().ToLower(), "%" + surname) select row;
Thus can you tell me show me some code on what you would change here in the linq to sql code?
View the full article