Solved

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

Posted on 2011-03-13
8
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

627 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