TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nalini Raghavan
NA
25
3.1k
Getting an error when trying to retrieve data from the datab
Oct 11 2017 2:38 PM
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;
}
Reply
Answers (
3
)
cache removal from browser in dot net
Akka.net Vs Web API