Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-13
8
Medium Priority
?
699 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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 23

Accepted Solution

by:
Snarf0001 earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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