I have many TextBOX in asp.net which accepts the value from user and stores it to SQL DB through SQL SERVER..
When the user does not enter the value in the textbox, Which means i can allow the null for that filed in the table, But if its integer variable it stores 0, thats because
int HostelFees ;
HostelFees = TextBox1.Text;
//function called to store the hostel fee
insertFee(hostelFees);
in Database it stores 0, which i dont want but it to be null..
I went through many documentations and understood only slightly about ISDBNULL, But still am confused regarding while inserting how i will insert null. 🙁 and i am not using any stored procedure’s.. infact in the function insertFee(hostelFees) i just use command.ExecuteNonQuery to insert it
Please can anyone give me proper explation or link which i refer.
Thank you,
You should consider using
int?, which is a nullable version ofint. In that case, you can use theHostelFees.HasValuecheck to see if a null is stored, andHostelFees.Valueto use the integer part.Please note that in your sample you are directly storing a string value into an integer variable. That won’t work. What you want is to parse it first, then store
nullif it’s not an integer. Something like this:And instead of assigning the integer value directly to the DbParameter, you can use the following construction: