I have a table that stores last name, middle name and first name. I insert values in these columns using a stored procedure. But for those whose names doesn’t have middle name like Marry Jones, Laite Manuel, etc, when I click into insert button, the stored procedure reports an error saying: it expects @MiddleName which was not specified. How can I solve this?
The stored procedure contains the following code:

…
@FirstName varchar(50),
@MiddleName varchar(50),
@LastName varchar(50)
AS
BEGIN
(
FirstName ,
MiddleName,
LastName 
)

VALUES
(
@FirstName ,
@MiddleName,
@LastName 
)
END

My InsertNamesaspx page contain an insert button, an insertReportLabel (Label) and the following ID names of textboxes:
firstNameTexxBox – for editing first names;
middleNameTexxBox - for editing middle names;
lastNameTexxBox - for editing last names.
Please help.

Recommended Answers

All 3 Replies

if the middle name is blank and you are facing error then you have to set that feild in SQL database as a default vale to "" so it will not give you any error..

Essentially you're asking it to send a variable that for all intents and purposes does not exist. One option is to try what flexibleres suggested and set a default value so that it is going to send at least NULL to the stored proc. If you want to get more complicated you can set some basic error handling in your page-side script that checks for a value in the middle name and if there is none, THEN sends NULL to the stored proc. Either way, as long as at least NULL is sent (as opposed to nothing, which is vastly different) you shouldn't get this error.

The only catch here being that you cannot have a Not Null qualifier on your table column or it will REQUIRE a value no matter what, and NULL will not suffice.

i think you have set the "middle name" field in the DB as "not null" and thats why it wont let you enter null values

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.