Solved

Procedure or function 'AddItem' expects parameter '@itemImage', which was not supplied.

Posted on 2011-03-13
8
667 Views
Last Modified: 2012-05-11
When I execute a stored procecure, I get the above error. itemImage field in the db is varchar and allow null values. I want to add value only if FileUpload1 has any file.

cmd.Parameters.Add("@itemImage", SqlDbType.VarChar, 50);

        if (FileUpload1.HasFile)
        {
            cmd.Parameters["@itemImage"].Value = txtItem.Text + System.IO.Path.GetExtension(FileUpload1.FileName);  <--------------- error here
        }

How can I solve the problem?

thanks

ayha
0
Comment
Question by:ayha1999
8 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 35122100
You are specifying a parameter without setting a value, if it's to be null if there is no file then you need to state this.  So try the following attached code
if (FileUpload1.HasFile)
{
    cmd.Parameters["@itemImage"].Value = txtItem.Text + System.IO.Path.GetExtension(FileUpload1.FileName);  <--------------- error here
}
else
{
    cmd.Parameters["@itemImage"].Value = null;
}

Open in new window

0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 35122104
Sorry remove the  "<--------------- error here" part :-)
0
 
LVL 7

Author Comment

by:ayha1999
ID: 35122293
I have alraedy tried that but same error.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 35122640
Have you put in your stored procedure that the itemImage parameter is nullable?
0
 
LVL 7

Author Comment

by:ayha1999
ID: 35122758
no.

if I try the follwoing with a textBox instead of FileUpload1, it works.

 if (FileUpload1.HasFile)
{
    cmd.Parameters["@itemImage"].Value = txtItem.Text;
else
{
    cmd.Parameters["@itemImage"].Value =txtItem.Text;
}

I think 'null' is acceptable.
0
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 250 total points
ID: 35122988
You need to use DBNull.Value.

If you pass a .net null as the parameter value, the parameter won't be used at all, and throw the missing error.
Try doing this:

else
{
  cmd.Parameters["@itemImage"].Value = DBNull.Value;
}

That will put a "sql" null as the value.
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35125493
Hello, you have to first confirm about what type of image data do you want to store the image or only its path. If you want to store the image it is compulsory to set the datatype at int and you must convert the image into binary format, after that you have to store the image into database.

or

If you want to store only path of an image. It is very easy to store set the datatype into nvarchar(max) and store the whole path of an image into it.
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35129232
it worked.

thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question