0

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.

Edited by __avd: Added [code] tags.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by himanshu.1691
0

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..

0

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.

Edited by Lusiphur

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.