Hi, I have spent many days for a way to rectify a Null binding error I am getting. Hence why I am posting this Q here. I am getting my ideas and code from Mike's book tutorial and an evonet tutorial.
The problem I have is that if I put the code inside an if...else statment, the variables are not visible to modal form I am trying to generate.
This is the code at the top of the page (DiscountCustomers.cshtml)
/* ------------ variables to edit discount data ------------*/
var query4 = "Select * FROM dbo.tblPromos Where CustomerCode=@0";
var data4 = db.QuerySingle(query4, CustomerCode);
var sid = data4.SalesID;
var emdiscount = data4.Discount;
var emvat = data4.VAT;
var emvatrate = data4.VATRate;
var emiscription = data4.iscription;
var emsrpbasedon = data4.SRPBasedOn;
if(IsPost){
emdiscount = Request["discount"];
emvat = Request["VAT"];
emvatrate = Request["vatrate"];
emsrpbasedon = Request["srpbasedon"];
emiscription = Request["iscription"];
var emsql = "UPDATE dbo.tblPromos SET Discount=@0, VAT=@1, VATRate=@2, SRPBasedOn=@3, iScription=@4 WHERE SalesID=@5";
db.Execute(emsql, emdiscount, emvat, emvatrate, emiscription, emsrpbasedon, sid);
}
This is the code I am using for the modal form also in DiscountCustomers.cshtml:
What null errror? Which line of code causes it? If it is any of the variable assignments being made from data4, that suggests that no data was returned from the database. You should check to see if CustomerCode has the vale that you expect it to have.
Its because you mainly need to create public variables out of your if else block like
var public = "";
if(publicImage == true) {//just assume it, don't go for reason
public == true;
}
This way, if your publicImge is not true still public will have an empty value! This way the database will have an empty column but not null. Nulls are created when you don't work on a col! They can be handled by
if(publicImage == null) {
public = false;
}
This way you won't get the error because the code will check whether the value is null or not! This way it only write the code on page if its empty or filled not null! Don't miss Null and Empty. (Someone please correct me about empty and nulls, Mike you're here so please)
Null can be seen on the col value written in italics, but empty is just an empty field!
So next time the null error shows up please bind that code block in an if statement with this code
if(variable != null) {
// your work..
}
Read more of my web development posts on my website. Thank you.
Member
52 Points
252 Posts
Help me rectify a Null error?
May 15, 2013 05:39 AM|Liquidmetal|LINK
Hi, I have spent many days for a way to rectify a Null binding error I am getting. Hence why I am posting this Q here. I am getting my ideas and code from Mike's book tutorial and an evonet tutorial.
The problem I have is that if I put the code inside an if...else statment, the variables are not visible to modal form I am trying to generate.
This is the code at the top of the page (DiscountCustomers.cshtml)
This is the code I am using for the modal form also in DiscountCustomers.cshtml:
I really need someone to help/guide me.
Thank you.
All-Star
194032 Points
28035 Posts
Moderator
Re: Help me rectify a Null error?
May 15, 2013 07:57 AM|Mikesdotnetting|LINK
What null errror? Which line of code causes it? If it is any of the variable assignments being made from data4, that suggests that no data was returned from the database. You should check to see if CustomerCode has the vale that you expect it to have.
Member
20 Points
7 Posts
Re: Help me rectify a Null error?
Jul 08, 2013 06:13 AM|Krishna.kv|LINK
Request["discount"] or Request["emdiscount"] Check if that is the null value.
Member
445 Points
176 Posts
Re: Help me rectify a Null error?
Jul 09, 2013 02:31 AM|mhcodner|LINK
Maybe you should check for null values in your database table
Contributor
4010 Points
1926 Posts
Re: Help me rectify a Null error?
Jul 09, 2013 01:16 PM|Afzaal.Ahmad.Zeeshan|LINK
Its because you mainly need to create public variables out of your if else block like
This way, if your publicImge is not true still public will have an empty value! This way the database will have an empty column but not null. Nulls are created when you don't work on a col! They can be handled by
This way you won't get the error because the code will check whether the value is null or not! This way it only write the code on page if its empty or filled not null! Don't miss Null and Empty. (Someone please correct me about empty and nulls, Mike you're here so please)
Null can be seen on the col value written in italics, but empty is just an empty field!
So next time the null error shows up please bind that code block in an if statement with this code