Click here to Skip to main content
14,773,088 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
    <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" />

publiv void insertData()
SqlConnection con = new SqlConnection(str_con);
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

Stored procedure:-
ALTER procedure [dbo].[InsertInfo]
	@s_name varchar(300),
	@s_phone int,
	@s_degree varchar(300)
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.
Updated 25-Oct-20 13:40pm
Comments 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

I got it.. There is no issue in your code. Remove the last line in your stored procedure :dead:
ALTER procedure [dbo].[InsertInfo]
@s_name varchar(300),
@s_phone int,
@s_degree varchar(300)
insert into info(s_name,s_phone,s_degree) values(@s_name,@s_phone,@s_degree)
exec InsertInfo----------THIS LINE
Comments 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?
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.

07navneet 5-Dec-11 5:25am
If its so simple then how??
I think not passing the Value @s_name when calling stored Procedure

Here getting Value
string a = Convert.ToString(txtName.Text);
07navneet 5-Dec-11 5:32am
Abhi KA 5-Dec-11 5:43am
not get the values
Check for this three simple problem

1.Having not passing parameter to Sql server stored procedure from
2.Set proper CommandType to StoredProcedure .
3.DBNull Value to output parameter.

for more details on this topic you can check on DataHaunting Procedure or function expects parameter which was not supplied
CHill60 17-Jun-14 13:17pm
Bit late with the response. Question is well over 2 years old ... and is resolved

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