Solved

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

Posted on 2011-03-13
8
642 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
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 35122640
Have you put in your stored procedure that the itemImage parameter is nullable?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now