I have a form and stored procedure that inserts the data from the form. It works fine except that if a field isn\'t filled in it doesn\'t insert a NULL
into SQL
While creating stored procedure make those columns as null which can be null.. like
CREATE PROCEDURE [dbo].[USP_TDS_SaveRecod]
@ID INT,
@CODE INT,
@FIRSTNAME VARCHAR(8)=NULL,
@CITY VARCHAR(15)=NULL
AS
BEGIN
.........................
.........................
.........................
END
and then in code don't add those parameters which are null..
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = obj.ID;
cmd.Parameters.Add("@CODE", SqlDbType.Int).Value = obj.CODE;
if(pd_first_name.Text != "")
{
cmd.Parameters.Add("@FIRSTNAME", SqlDbType.VarChar).Value = pd_first_name.Text;
}
if(city.Text != "")
{
cmd.Parameters.Add("@CITY", SqlDbType.VarChar).Value = pd_first_name.Text;
}