Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

Monday, May 2, 2016

Inner Join using LINQ



Create query:


var queryOfficeInfo = from ofc in db.Offices
join llo in db.LLOs
on ofc.Office_Name equals llo.LLO_Name
select new
{
ofc.Office_ID,
llo.tp_ID,
ofc.Office_Name
};



Retrieve Query:



var result = queryOfficeInfo.Where(q => q.tp_ID.Equals(obj.LLO_ID));
//Update the FCJC Record to reflect correct office relationship


obj.Office_ID = result.Select(a => a.Office_ID).FirstOrDefault();



Wednesday, March 11, 2015

Linq where clause for SQL Lite

I was trying to get the syntax for a SQL Lite query. Passing in the id of an record for a standard CRUD operation. 

public Report GetReport(int itemId)
{
return _connection
.Table<Report>()
.Where(x => x.Id == itemId)  
.FirstOrDefault();
}

Source
http://stackoverflow.com/questions/6359980/proper-linq-where-clauses

Wednesday, July 16, 2014

Connection string sytnax for IIS to SQL Server connection.

I always forget the syntax for connnection strings in my applications.  The guys at connectionsstrings.com do a great job but stumbled across another way to get at the correct syntax.


The steps below.


1.     Right-click an empty spot on the desktop and choose NEW, TEXT DOCUMENT from the context menu


2.     Save it with a .udl extension, and click yes when it asks are you sure.


3.     Double-click the new udl file you just created. It will open a dialogue. Go to the Provider tab, and choose the appropriate provider.


4.     Go to the Connection tab and fill in the server name and database name, and choose NT authentication (or use a specific username and password, which is SQL authentication). Now click Test Connection. If it works, you're ready to click OK and move on to the final step. If it doesn't you need to resolve permission issues, or you've mis-typed something.

5.     Now right-click the file on the desktop and open it in notepad. It will display the connection string that you can copy and paste to wherever you need it.