Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello

Plz help me with this.

Procedure or function 'sp_SqlImage' expects parameter '@ID', which was not supplied.

I have declared the parameter ID in Sql procedure also created in table.

But i get this error plz help

My code is
C#
public partial class TableAdd : System.Web.UI.Page
    {
        DataSet ds = new DataSet();

        SqlConnection con;
        SqlCommand cmd = new SqlCommand();
        SqlParameter sp1 = new SqlParameter();
        SqlParameter sp2 = new SqlParameter();
        SqlParameter sp3 = new SqlParameter();
        SqlParameter sp4 = new SqlParameter();
        SqlParameter sp5 = new SqlParameter();
        SqlParameter sp6 = new SqlParameter(); 
   }

----------------------------------------------------------
This is the add button on the page.:
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           con = new SqlConnection("server=203.199.15.181; database= commonlogin;uid=sa;pwd=nirwan612");
           //cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value =Convert.ToInt32( txtID.Text);
           cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
           cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtDesc.Text;
           cmd.Parameters.Add("@Image", SqlDbType.Binary).Value = txtImage.Text;
           cmd.Parameters.Add("@Active", SqlDbType.VarChar).Value = txtActive.Text;
           cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = txtCreatedBy.Text;
           cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = txtCreDate.Text;
           cmd=new SqlCommand ("sp_SqlImage", con);
           cmd.CommandType =CommandType.StoredProcedure;



           con.Open();
           cmd.ExecuteNonQuery ();
           con.Close();
       }

------------------------------------------------
Posted
Updated 12-Jun-12 19:41pm
v2
Comments
amolpatil2243 13-Jun-12 1:43am    
Your @ID parameter is commented, remove comment
tanweer 13-Jun-12 1:44am    
hi, remove comment from this line and test:
cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value =Convert.ToInt32( txtID.Text);
Nischal Bhatt 13-Jun-12 1:47am    
Hi! I would check the application code and see what value i'm setting @Image to. I suspect it is null and therein lies the problem.
Nikil0012 13-Jun-12 1:47am    
I have tried that already, but same error, plz help
tanweer 13-Jun-12 1:53am    
you have used the datatype of the parameter SqlDbType.BigInt, check it in the procedure is it the same there??

You have commented out this line:
C#
//cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value =Convert.ToInt32( txtID.Text);


Uncomment it and set the correct value. Error tells that Stored Procedure does have ID as one of the parameter defined and you need to pass it along with others from your code.
 
Share this answer
 
Comments
Nikil0012 13-Jun-12 1:47am    
I have tried that already, but doesn't work, plz help
0. your stored procedure expects a parameter called @id.
1. you have a line commented which perhaps is needed to supply the @ID parameter.
2.

your class contains this

C#
SqlCommand cmd = new SqlCommand();


then on button click

C#
con = new SqlConnection("server=203.199.15.181; database= commonlogin;uid=sa;pwd=nirwan612");
           //cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value =Convert.ToInt32( txtID.Text); <----Uncommenting this probably should work, also see one comment below in same code block
           cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
           cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtDesc.Text;
           cmd.Parameters.Add("@Image", SqlDbType.Binary).Value = txtImage.Text;
           cmd.Parameters.Add("@Active", SqlDbType.VarChar).Value = txtActive.Text;
           cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = txtCreatedBy.Text;
           cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = txtCreDate.Text;
           cmd=new SqlCommand ("sp_SqlImage", con); //<----------WHAT and WHY THIS?
           cmd.CommandType =CommandType.StoredProcedure;


Why are you doiing a new on command after adding so many parameters to it. instead you should do

C#
cmd.Connection = con;
cmd.CommandText = "sp_SqlImage";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900