Click here to Skip to main content
15,302,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Procedure or function 'SubmitRecord' expects parameter '@name', which was not supplied.

What I have tried:

C#
try
            {
                cnn.Open();
                SqlCommand cmd=new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd = new SqlCommand("SubmitRecord", cnn);
                cmd.Parameters.AddWithValue("@name",txtname.Text);
                cmd.Parameters.AddWithValue("@about",txtabout.Text);
                cmd.Parameters.AddWithValue("@address", txtaddress.Text);
                cmd.Parameters.AddWithValue("@email",txtemail.Text);
                cmd.Parameters.AddWithValue("@mobile", txtcno.Text);
                cmd.Parameters.AddWithValue("@refname", txtrefname.Text);
                cmd.Parameters.AddWithValue("@areyou",DropDownList1.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("@interest",interests);
                cmd.Parameters.AddWithValue("@anyother",txtanyother.Text);
                cmd.Parameters.AddWithValue("@quote",quote);
                cmd.Parameters.AddWithValue("@sharenews",sharenews);
                cmd.Parameters.AddWithValue("@remark", txtremark.Text);
                cmd.Parameters.AddWithValue("@pass",pass);
               
                cmd.Parameters.AddWithValue("@typeofsub", sub);
                
                
               
                cmd.ExecuteNonQuery();

stored procedure:

ALTER PROCEDURE [dbo].[SubmitRecord]
(
@name	varchar(50),	
@about	nvarchar(MAX),	
@address	varchar(200),	
@email	varchar(50)	,
@mobile varchar(20),
@refname	varchar(50),	
@areyou	varchar(50),	
@interest	varchar(MAX),	
@anyother	varchar(MAX),	
@quote	varchar(50),	
@sharenews	varchar(50),	
@remark	varchar(MAX),	
@pass	varchar(50),	
@typeofsub	varchar(50)
)	
AS
INSERT INTO [Businessnews].[dbo].[tbl_register]
           ([name]
           ,[about]
           ,[address]
           ,[email]
           ,[mobile]
           ,[refname]
           ,[areyou]
           ,[interest]
           ,[anyother]
           ,[quote]
           ,[sharenews]
           ,[remark]
           ,[pass]
           ,[regdate]
           ,[typeofsub])
     VALUES(@name,@about,@address,@email,@mobile,@refname,@areyou,@interest,@anyother,@quote,@sharenews,@remark,
@pass,
GETDATE(),		
@typeofsub
)
Posted
Updated 6-Feb-16 15:33pm
v2
Comments
[no name] 6-Feb-16 5:38am
   
You have 14 Params in SP, but you set only 13. Seems "typeofsub" you forgot. Maybe the error message is not exact enough as it should be...

Put a breakpoint on the line:
C#
cmd.Parameters.AddWithValue("@name",txtname.Text);

And look at exactly what the textbox holds: the error may be that the content is missing - in which case you need to check your user input instead of just passing it thourgh unchecked.
   
May be txtname passing value null.
you can handle null values in stored procedure

Check out code just set default value to parameter
(='' for string data type) (=0 for integer)

SQL
ALTER PROCEDURE [dbo].[SubmitRecord]
(
@name varchar(50)='',
@about nvarchar(MAX)='',
)

might be above code will help you sort out the problem
   
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