Hello,
This is the error i get when I try to retrieve data from the database.
"The cast to value type 'Single' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type."
Here is my code:
- public JsonResult AjaxInventory()
- {
-
- FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
-
- string[] UserData = ticket.UserData.Split('|');
-
-
-
-
- var result = dbGetItemsList(UserData[4], UserData[2]);
-
-
- return Json(new
- {
-
-
-
-
- data = result
- }
- );
- }
-
- private List dbGetItemsList(string electionID, string candidateId)
- {
-
-
- List lstItems = dbFFS.Database.SqlQuery
- ("sp_GetContributions @electionId, @candidateId, @officeId, @contributionId,@contributorId, @receiptNoFrom, @receiptNoTo, @amountFrom, @amountTo, @acceptionTimeFrom, @acceptionTimeTo, @contributorTypeAbbr, @relationshipAbbr, @contributionTypeAbbr, @deliveryMethodAbbr",
- new SqlParameter("@electionId", electionID),
- new SqlParameter("@candidateId", candidateId),
- new SqlParameter("@officeId", 7),
- new SqlParameter("@contributionId", 1),
- new SqlParameter("@contributorId", 26),
- new SqlParameter("@receiptNoFrom", DBNull.Value),
- new SqlParameter("@receiptNoTo", DBNull.Value),
- new SqlParameter("@amountFrom", DBNull.Value),
- new SqlParameter("@amountTo", DBNull.Value),
- new SqlParameter("@acceptionTimeFrom", DBNull.Value),
- new SqlParameter("@acceptionTimeTo", DBNull.Value),
- new SqlParameter("@contributorTypeAbbr", DBNull.Value),
- new SqlParameter("@relationshipAbbr", DBNull.Value),
- new SqlParameter("@contributionTypeAbbr", DBNull.Value),
- new SqlParameter("@deliveryMethodAbbr", DBNull.Value)
- ).ToList();
-
-
-
-
-
-
- return lstItems;
- }