Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
Getting an error when trying to retrieve data from the datab
Nalini Raghavan
7y
206
1
Reply
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()
{
//Get the id of active election
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
//0 Username | 1 Fullname | 2 User Id | 3 Login Type | 4 Election Id
string
[] UserData = ticket.UserData.Split(
'|'
);
// action inside a standard controller
//int filteredResultsCount;
//int totalResultsCount;
//Load information
var result = dbGetItemsList(UserData[4], UserData[2]);
//totalResultsCount = result.Count;
//filteredResultsCount = totalResultsCount;
return
Json(
new
{
// this is what datatables wants sending back
//draw = 1,
//recordsTotal = totalResultsCount,
//recordsFiltered = filteredResultsCount,
data = result
}
//, JsonRequestBehavior.AllowGet
);
}
private
List dbGetItemsList(
string
electionID,
string
candidateId)
{
//SqlParameter param1 = new SqlParameter("@candidateId", candidateID);
//ElectionID = @electionId and
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();
//Call Stored Procedure
//List lstItems = db.Database.SqlQuery(
// "GetWebInventoryList @electionId, @candidateId",
// new SqlParameter("electionId", electionID),
// new SqlParameter("candidateId", candidateID)
// ).ToList();
return
lstItems;
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
cache removal from browser in dot net
Akka.net Vs Web API