473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

stored procedure parameter expected error !!!

bansari
20
Hi..i tried to make insert stored procedure.
-------------------------------------------------------
ALTER PROCEDURE [dbo].[insert_empdata]

(
@empno int,
@empname varchar(100),
@emppassword varchar(100),
@empdob varchar(100)
)

AS

BEGIN
insert into Emp_3Tier values(@empno,@empname,@emppassword,@empdob)

END
-----------------------------------------------------

when i click my button on my webpage i found such error message:

Procedure 'insert_empdata' expects parameter '@empno', which was not supplied.

My aspx code is as below :
---------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. //using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. //using System.Xml.Linq;
  13. using System.Data.SqlClient;
  14.  
  15.  
  16. public partial class EmpDetails : System.Web.UI.Page
  17. {
  18.  
  19.  
  20.     SqlConnection con;
  21.     SqlCommand cmd = new SqlCommand();
  22.  
  23.     SqlParameter sp1, sp2, sp3, sp4;
  24.  
  25.  
  26.     protected void Page_Load(object sender, EventArgs e)
  27.     {
  28.         if (!Page.IsPostBack)
  29.         { 
  30.  
  31.         }
  32.     }
  33.     protected void btnInsert_Click(object sender, EventArgs e)
  34.     {
  35.  
  36.  
  37.         con = new SqlConnection("Data Source=10.0.32.33;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=abcdef");
  38.  
  39.         int emp_no= Convert.ToInt16(txtEmpNo.Text);
  40.         string emp_name=txtEmpName.Text;
  41.         string emp_pass =txtpassword.Text;
  42.         string emp_dob=ddlDay.Text + "-" + ddlMonth.Text + "-" + txtYear.Text;
  43.  
  44.         sp1 = new SqlParameter("@empno", emp_no);
  45.         sp2 = new SqlParameter("empname", emp_name);
  46.         sp3 = new SqlParameter("@emppassword", emp_pass);
  47.         sp4 = new SqlParameter("@empdob", emp_dob);
  48.  
  49.  
  50.         cmd = new SqlCommand("insert_empdata", con);
  51.         cmd.CommandType = CommandType.StoredProcedure;
  52.  
  53.         try
  54.         {
  55.             con.Open();
  56.             cmd.ExecuteNonQuery();
  57.         }
  58.         catch (Exception ex)
  59.         {
  60.             Response.Write("error occured " + ex.Message);
  61.         }
  62.         finally
  63.         {
  64.             con.Close();
  65.         }
  66.  
  67.  
  68.  
  69.     }
  70. }
  71.  
  72.  
---------------------------------------------------------

plz help.thanks in advance.
Oct 5 '10 #1

✓ answered by Subin Ninan

Error is because you have not assigned parameters with command object.

It should be something like this:
Expand|Select|Wrap|Line Numbers
  1. cmd = new SqlCommand("insert_empdata", con);
  2.  
  3.  
  4. SqlParameter empno = cmd.Parameters.Add("@empno", dbtype.int);
  5.  
  6.  
  7. empno.Value = 0062;
  8.  
  9.  
  10. cmd.CommandType = CommandType.StoredProcedure;
  11.  
  12.  
  13. cmd.ExecuteNonQuery();
  14.  

3 1475
Error is because you have not assigned parameters with command object.

It should be something like this:
Expand|Select|Wrap|Line Numbers
  1. cmd = new SqlCommand("insert_empdata", con);
  2.  
  3.  
  4. SqlParameter empno = cmd.Parameters.Add("@empno", dbtype.int);
  5.  
  6.  
  7. empno.Value = 0062;
  8.  
  9.  
  10. cmd.CommandType = CommandType.StoredProcedure;
  11.  
  12.  
  13. cmd.ExecuteNonQuery();
  14.  
Oct 5 '10 #2
mzmishra
390 Expert 256MB
You have defined the parameters but you are not adding that to you sqlcommand object.
Oct 5 '10 #3
bansari
20
Thank you So much!! :)
Oct 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Steven | last post by:
I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a...
1
by: mikeyatsony | last post by:
Hi all.. I'm trying to send multiple INT values to a Stored Procedure that will be handled in an IN statement. ASP Code: strSQL = "SP_Get_Selections '29, 32' where 29 and 32 are 2 integer...
1
by: ElmoWatson | last post by:
I'm getting an error I don't understand.... Here's my Code: Dim dr As SqlDataReader Dim retVal As Boolean = False Dim MySQL as string = "spGetEmployee" Dim Myconn as New...
6
by: Bala | last post by:
Hi, This is my stored procured. i try to pass the parametre like this. i am getting error. any one please tell me how to pass the parameter? vb code: ..Connection = New...
1
by: Peter Kirk | last post by:
Hi should I be able to set the value for a parameter to a stored procedure to null? For example: IDataParameter param = command.CreateParameter(); param.ParameterName = "@id"; param.Value =...
1
by: JLE | last post by:
I'm new to stored procedures, however, the passing of parameters using a group item in the calling cobol program seems incorrect to me. Would this work? Calling COBOL pgm is calling a stored...
7
by: CK | last post by:
I want the procedure to check for the existence of a paramter and if it is there, it will process these instructions, otherwise it will process these instructions. Any ideas? Thanks for your...
8
by: ZRexRider | last post by:
Hi, I have a .NET application that I want to save the Config.EXE contents to my SQL database for remote review/testing. This config file is 3700+ bytes long. I created a field in one of my...
2
by: PRITHA | last post by:
Hello, I have used stored procedure with parameters.Now I want to use the parameter in the select statement.Following is my code in the procedure. //////////////////////////////////// CREATE...
2
by: kxyz | last post by:
Hello everyone, I need help with a stored procedure or two. My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.