Deal of the Day

Home » Main » Manning Forums » 2007 » LINQ in Action

Thread: Want a pass thru query example

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 0 - Pages: 1
slindee

Posts: 28
From: La Crosse, WI
Registered: 4/22/08
Want a pass thru query example
Posted: Dec 9, 2008 9:29 PM
  Click to reply to this thread Reply

I want to write a generalized pass-thru query where the SQL statement is passed to the LINQ function from the caller. What should the Dim query As .... be to make this work? Code below:
Public Shared Function ExecuteSQL(ByVal strModuleConnectionString As String, _
ByVal strSQL As String) As DataTable
Dim dt As New DataTable
Try
Dim dc As New dcModuleDataContext(strModuleConnectionString)
Dim query As System.Linq.IOrderedQueryable
query = dc.ExecuteQuery(strSQL)
dt = query.CopyToDataTable
Catch exc As Exception
Call WinExcept.ExceptionHandler.Exception(clinqModule, exc)
dt = Nothing
Finally
End Try
Return dt
End Function

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor