Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
I made this simple example of inserting data in DB using procedure but always getting this error
Procedure or Function 'InsertInfo' expects parameter '@s_name', which was not supplied.

Catch is that data is inserted in the table but error is shown!
HTML file
:-
XML
<div>
    <asp:Label runat=server>Name</asp:Label>
    <asp:TextBox runat=server ID="txtName"></asp:TextBox><br />
    <asp:Label runat=server>Phone No.</asp:Label>
    <asp:TextBox runat=server ID="txtPhone"></asp:TextBox><br />
    <asp:Label runat=server>Degree in:</asp:Label>
    <asp:TextBox runat=server ID="txtDegree"></asp:TextBox><br />
    <asp:Button runat=server ID="btnSubmit" Text="Submit" onclick="btnSubmit_Click"/>
    <asp:Button runat=server ID="btnEdit" Text="Edit" />
    </div>


Code(.cs):-
publiv void insertData()
{
SqlConnection con = new SqlConnection(str_con);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "InsertInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
string a = Convert.ToString(txtName.Text);
int b = Convert.ToInt32(txtPhone.Text);
string c = txtDegree.Text;
cmd.Parameters.Add("@s_name", SqlDbType.VarChar).Value = a;
cmd.Parameters.Add("@s_phone", SqlDbType.Int).Value = b;
cmd.Parameters.Add("@s_degree", SqlDbType.VarChar).Value = c;
//cmd.Parameters.AddWithValue("@s_name", a);&lt;------tried with these also
//cmd.Parameters.AddWithValue("@s_phone", b);
//cmd.Parameters.AddWithValue("@s_degree", c);
cmd.ExecuteNonQuery();&lt;-------error points here
con.Close();
}


Stored procedure:-
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertInfo]
(
	@s_name varchar(300),
	@s_phone int,
	@s_degree varchar(300)
)
as
insert into info(s_name,s_phone,s_degree) values(@s_name,@s_phone,@s_degree)
exec InsertInfo

I beg to you, please help me find the error.
Posted
Updated 12-Mar-21 23:21pm
v3
Comments
sriman.ch 5-Dec-11 5:12am    
Have you chekced the values of the corresponding textboxes are not null or empty? Try to debug the code once and see whether you are able to fill the parameters or not ?
07navneet 5-Dec-11 5:25am    
The parameters are filled(I am not able to show to you the 'print screen' image at time of debugging) with their corr.values
[no name] 5-Dec-11 20:17pm    
EDIT: added "pre" tag

Error -

/2021/Step5.aspxProcedure or function 'usp_studentdetails_insert_Fee_Details' expects parameter '@pdffile', which was not supplied.
 
Share this answer
 
Comments
Richard Deeming 15-Mar-21 9:40am    
Your error message is not a "solution" to anyone else's question!
I got it.. There is no issue in your code. Remove the last line in your stored procedure :dead:
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertInfo]
(
@s_name varchar(300),
@s_phone int,
@s_degree varchar(300)
)
as
insert into info(s_name,s_phone,s_degree) values(@s_name,@s_phone,@s_degree)
exec InsertInfo----------THIS LINE
 
Share this answer
 
Comments
sriman.ch 5-Dec-11 5:44am    
spot on...5!
07navneet 5-Dec-11 5:56am    
!!!!!!!!!! You are really a MVP, sir!
Caught the error in one shot! I was struggling with this type of problem since a month but couldn't find answer! I thought about this answer but I guessed that this is the syntax for procedure.
Thanks a lot!!!
07navneet 5-Dec-11 5:58am    
One more help, sir. I am learning ASP.NET by myself but not able to cope up with such problems. What should be the way to learn and master this, so that job will not be a matter for me in 2012?
I think not passing the Value @s_name when calling stored Procedure

Here getting Value
string a = Convert.ToString(txtName.Text);
 
Share this answer
 
Comments
07navneet 5-Dec-11 5:32am    
???
Abhi KA 5-Dec-11 5:43am    
not get the values
This means you are not passing a value to @s_name when you are calling the stored procedure. You need to pass a valid parameter during SP execution.

Regards,
Eduard
 
Share this answer
 
Comments
07navneet 5-Dec-11 5:25am    
If its so simple then how??

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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