473,388 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to Insert null from TextBox to integer Field

I have a text box and datetime where can i enter an integer . I wish to store this in a SQL Server Database. If i enter then I would store a NULL. However if the text box is left blank, I get an error Input string was not in a correct format. How can I work around this, and get the null into the db?

this Code in method

Expand|Select|Wrap|Line Numbers
  1. public void Add_ItemSeasonalPrices(string ItemCode, DateTime FromDate, DateTime ToDate, decimal WholeSaleForFirstUnit, decimal WholeSaleForSecondUnit, decimal WholeSaleForThirdUnit)
  2.     {
  3.         DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
  4.         DAL.open();
  5.         SqlParameter[] param = new SqlParameter[22];
  6.         param[0] = new SqlParameter("@ItemCode", SqlDbType.NVarChar, 25);
  7.         param[0].Value = ItemCode;
  8.  
  9.         param[1] = new SqlParameter("@FromDate", SqlDbType.DateTime);
  10.         param[1].Value = FromDate;
  11.  
  12.  
  13.         param[2] = new SqlParameter("@ToDate", SqlDbType.DateTime);
  14.         param[2].Value = ToDate;
  15.  
  16.  
  17.         param[3] = new SqlParameter("@WholeSaleForFirstUnit", SqlDbType.Decimal);
  18.         param[3].Value = WholeSaleForFirstUnit;
  19.  
  20.  
  21.         param[4] = new SqlParameter("@WholeSaleForSecondUnit", SqlDbType.Decimal);
  22.         param[4].Value = WholeSaleForSecondUnit;
  23.  
  24.  
  25.         param[5] = new SqlParameter("@WholeSaleForThirdUnit ", SqlDbType.Decimal);
  26.         param[5].Value = WholeSaleForThirdUnit;
  27.  DAL.ExecuteCommand("Add_ItemSeasonalPrices", param);
  28.         DAL.close();
  29.     }
and this Code in btnSave

Expand|Select|Wrap|Line Numbers
  1. Item.Add_ItemSeasonalPrices(txt_ItemCode.Text, Convert.ToDateTime(FromDate.Text), Convert.ToDateTime(ToDate.Text), Convert.ToDecimal(txt_WholeSaleForFirstUnit.Text), Convert.ToDecimal(txt_WholeSaleForSecondUnit.Text),
  2.                                             Convert.ToDecimal(txt_WholeSaleForThirdUnit.Text);
Apr 19 '16 #1
0 2613

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Keith | last post by:
I am Using Dreamweaver MX to create my site and have come accross a problem no one in the DW groups seems to be able to help with. When I submit an insert to my SQL database, any form value which...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
6
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime...
17
by: NuB | last post by:
I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank? example: I have 5 textboxes, and a user can leave some...
0
by: hemant123 | last post by:
Hi I Am Trying To Insert Null Value In Oracle Date Column Using Visual Basic 6 Textbox. I Tried Various Options But Unable To Insert. Please Advise Me A Solution. Thanks In Advance Hemant
1
by: hemant123 | last post by:
Hi I am trying to insert null value in date field using vbasic textbox.I tried various options but failed.Please tell me the solution. Thanks in advance. Hemant
3
by: rc | last post by:
How to insert NULL values in to int field using params. I'm trying to use pymssql.execute, passing the operation and list of params. One of the values in the params is a NULL value going to int...
1
by: billa856 | last post by:
Hi, I am trying to insert Null value in column(ShipDate) in my table.That column(ShipDate)'s type id date/time and format is short date. I am using "" to insert Null in that column(ShipDate)...
2
by: RN1 | last post by:
How do I insert NULL values in a SQL Server DB table in a column whose datatype is int? This is what I am trying currently (in the UpdateCommand event function of a DataGrid): ...
2
by: dmorand | last post by:
I have this query that I'm using in coldfusion: Insert into ps_manager_employee_ids (manager_emplid,emp_id,last_name,first_name,hire_dt,rehire_dt,emp_status,union_status) values...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.