title: Input string was not in a correct format error #2
body: <p>I have the following request:</p>
  <pre><code>   string sqlStr = @&quot;Select a.Text, a.TrackKey, a.NoteType, a.TranKey, a.TranType, 
      Case a.TranType when '1110' then 'https://www.cps/SAM/SO/RMA/RMAView.asp?key=' 
       when '502' then 'https://www.cps/SAM/AR/InvInqDetail.asp?Key=' 
       when '511' then 'https://www.cps/SAM/AR/InvInqDetail.asp?Key=' 
       when '801' then 'https://www.cps/SAM/AR/OrdInqDetail.asp?Key='
       when '1101' then 'https://www.cps/SAM/AP/POInqDetail.asp?key=' 
       when '1111' then 'https://www.cps/SAM/PO/TruckDetail.asp?truckkey=' 
       when '835' then 'https://www.cpsm/SAM/SO/RMA/RMAView.asp?key='  End HREF, 
      Case when a.TranType = '1110' then 'M'
       when a.TranType = '502' then 'W'
       when a.TranType = '511' then 'W' 
       when a.TranType = '1101' then 'B'
       when a.TranType = '1111' then 'B'
       when a.TranType = '835' then '('  
       when (a.TranType = '801' and a.NoteType = '9') then '{'
       when (a.TranType = '801' and a.NoteType = '8') then '(' End dataicon      
      From tamTrackrEngine a 
      Where a.CreateDate &gt; DATEADD(DAY, DATEDIFF(DAY, 0, GetDate()), 0) 
      AND (a.EmpKey = {0} OR a.EmpKey IS NULL)
      AND a.Text IS NOT NULL
      Order by a.CreateDate DESC&quot;;
  
      var trackrinfo = db.Database.SqlQuery&lt;TrackrData&gt;(sqlStr, empKey).ToList();
  
      var TrackrInfo = JsonConvert.SerializeObject(trackrinfo);
  
      Response.Write(TrackrInfo);
      HttpContext.Response.AppendHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);
      return new EmptyResult(); 
  </code></pre>
  <p>When I run this code I get the error:</p>
  <blockquote>
  <p>input string was not in a correct format.</p>
  </blockquote>
  <p>I have put in a simpler sql query and gotten my results back without any problems so I think it has to do with some of the quotes in my query.</p>
  <p>Here is my StackTrace:</p>
  <blockquote>
  <p>[FormatException: Input string was not in a correct format.]   System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) +10930058   System.String.Format(IFormatProvider provider, String format, Object[] args) +63   System.Data.Entity.Core.Objects.ObjectContext.CreateStoreCommand(String commandText, Object[] parameters) +790   System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal(String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters) +208   System.Data.Entity.Core.Objects.&lt;&gt;c__DisplayClass63<code>1.&lt;ExecuteStoreQueryReliably&gt;b__62() +45   System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func</code>1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +333   System.Data.Entity.Core.Objects.&lt;&gt;c__DisplayClass63<code>1.&lt;ExecuteStoreQueryReliably&gt;b__61() +140   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func</code>1 operation) +189   System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably(String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters) +335   System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery(String commandText, ExecutionOptions executionOptions, Object[] parameters) +61   System.Data.Entity.Internal.&lt;&gt;c__DisplayClass13<code>1.&lt;ExecuteSqlQuery&gt;b__12() +151   System.Lazy</code>1.CreateValue() +415   System.Lazy<code>1.LazyInitValue() +152   System.Lazy</code>1.get_Value() +75   System.Data.Entity.Internal.LazyEnumerator<code>1.MoveNext() +12   System.Collections.Generic.List</code>1..ctor(IEnumerable<code>1 collection) +381   System.Linq.Enumerable.ToList(IEnumerable</code>1 source) +58   SAM3.Controllers.SharedDataController.Trackr() in c:\Users\candicesteele\Source\Repos\SAM3\SAM3\Controllers\SharedDataController.cs:273   lambda_method(Closure , ControllerBase , Object[] ) +62   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary<code>2 parameters) +157   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary</code>2 parameters) +27   System.Web.Mvc.Async.AsyncControllerActionInvoker.b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22   System.Web.Mvc.Async.WrappedAsyncResult<code>2.CallEndDelegate(IAsyncResult asyncResult) +29   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +49   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32   System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3c() +50   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass45.b__3e() +225   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass45.b__3e() +225   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass30.b__2f(IAsyncResult asyncResult) +10   System.Web.Mvc.Async.WrappedAsyncResult<code>1.CallEndDelegate(IAsyncResult asyncResult) +10   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +49   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass28.b__19() +26   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1e.b__1b(IAsyncResult asyncResult) +100   System.Web.Mvc.Async.WrappedAsyncResult<code>1.CallEndDelegate(IAsyncResult asyncResult) +10   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +49   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27   System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13   System.Web.Mvc.Async.WrappedAsyncVoid<code>1.CallEndDelegate(IAsyncResult asyncResult) +36   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +54   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39   System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12   System.Web.Mvc.Async.WrappedAsyncVoid<code>1.CallEndDelegate(IAsyncResult asyncResult) +28   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +54   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10   System.Web.Mvc.MvcHandler.b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +21   System.Web.Mvc.Async.WrappedAsyncVoid<code>1.CallEndDelegate(IAsyncResult asyncResult) +36   System.Web.Mvc.Async.WrappedAsyncResultBase</code>1.End() +54   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155</p>
  <p>Source Error:</p>
  <p>Line 273 var trackrinfo = db.Database.SqlQuery(sqlStr, empKey).ToList();Line 274:Line 275:</p>
  </blockquote>