Arun kumar

Arun kumar

  • NA
  • 5
  • 1.1k

Reg: Visual studio shows Exception.......

Jul 25 2014 6:51 AM
I am a beginner to Ado.net and stored procedure. In stored procedure I assigned two parameter(parameter1  to pass value from C# textbox and parameter2as OUTPUT parameter ). but when I run that website it shows an exception that expects Parameter value didn't supplied.
 
My code :
 
 
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\arun_.net training\WebSite2\App_Data\samplw.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd =new SqlCommand();
SqlParameter sq1= new SqlParameter();
cmd.Parameters.Add("@parameter1", SqlDbType.NVarChar).Value=TextBox1.Text;
cmd.Connection=conn;
cmd.CommandText="StoredProcedure3";
cmd.CommandType=CommandType.StoredProcedure;
conn.Open();
cmd.ExecuteNonQuery();// shows exceptions in line 
TextBox2.Text = (string)(cmd.Parameters["@parameter2"].Value);
conn.Close();
 
 Storedprocedure:
 
PROCEDURE dbo.StoredProcedure3
( @parameter1 VARCHAR(100)
,@parameter2 VARCHAR(200) OUTPUT)
AS
BEGIN
DECLARE @parameter3 VARCHAR(100)
SET @parameter3 = ' Your development resources.'
IF @parameter1 IS NOT NULL AND LEN(@parameter1) > 1
SELECT @parameter2 = 'The '
+ @parameter1
+ @parameter3
ELSE SELECT @parameter2 = 'CodeProject is cool!'
RETURN
END
 
I am beginner please recommend any link to read stored procedure .  
 

Answers (2)