Solved

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

Posted on 2011-03-13
8
657 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 36
SlingPlayer alternatives 1 36
SQL Login 17 41
C# Single Form 8 29
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

25 Experts available now in Live!

Get 1:1 Help Now