I have the following request:
string sqlStr = @"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 > 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";
var trackrinfo = db.Database.SqlQuery<TrackrData>(sqlStr, empKey).ToList();
var TrackrInfo = JsonConvert.SerializeObject(trackrinfo);
Response.Write(TrackrInfo);
HttpContext.Response.AppendHeader("Content-Type", "application/json");
return new EmptyResult();
When I run this code I get the error:
input string was not in a correct format.
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.
Here is my StackTrace:
[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.<>c__DisplayClass63
1.<ExecuteStoreQueryReliably>b__62() +45 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func
1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +333 System.Data.Entity.Core.Objects.<>c__DisplayClass631.<ExecuteStoreQueryReliably>b__61() +140 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func
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.<>c__DisplayClass131.<ExecuteSqlQuery>b__12() +151 System.Lazy
1.CreateValue() +415 System.Lazy1.LazyInitValue() +152 System.Lazy
1.get_Value() +75 System.Data.Entity.Internal.LazyEnumerator1.MoveNext() +12 System.Collections.Generic.List
1..ctor(IEnumerable1 collection) +381 System.Linq.Enumerable.ToList(IEnumerable
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, IDictionary2 parameters) +157 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3c() +50 System.Web.Mvc.Async.<>c__DisplayClass45.b__3e() +225 System.Web.Mvc.Async.<>c__DisplayClass45.b__3e() +225 System.Web.Mvc.Async.<>c__DisplayClass30.b__2f(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass28.b__19() +26 System.Web.Mvc.Async.<>c__DisplayClass1e.b__1b(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36 System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36 System.Web.Mvc.Async.WrappedAsyncResultBase
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& completedSynchronously) +155Source Error:
Line 273 var trackrinfo = db.Database.SqlQuery(sqlStr, empKey).ToList();Line 274:Line 275:
empKey
? – Rahul