sql - using isDBNULL to store null back in the database -


I have a textbox in many asp.net that accepts the value from the user and sends it to SQL Server via SQL Server When the user does not enter the value in the text box, which means that I can allow the null to be filed in the table, but if its integer variable stores it 0, then because < / P>

  int HostelFees; HostelFees = Text box 1 text; // Forum is asked to put hostel fees in FIE (hostel fees); It stores 0 in the database, which I want, but it is not empty. I went through several documents and understood only a bit about ISDBNLL, but still how I insert the null: (And I'm not using any stored procedure. Just type in the function  insertFee (hostelfixes) . I use it command. To do the sequence of non-sequential 

>

Should you consider int? , which is one of the int . In that case, you can call HostelFees.HasValue You can use to see if a blank is stored, and HostelFees.Value to use the integer part.

Please note that in your sample you can directly A string value is one If you want to parse it first, then store null if it is not an integer then something like this:

  int? HostelFees = null; Int parsedValue; If (int.TryParse (Textbox1.Text, out parsedValue)) {HostelFees = parsedValue}} // function is asked to deposit hostage fee (hostelFees); Instead of specifying an integer value directly to DbParameter, you can use the following construction:  
  parameter.value = (HostelFees.HasValue? HostelFees.Value: DbNull.Value);  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -