Hi all help is needed.
this stored proc check if user exist, if it exist it will not insert but if it doesnt exist it insert. But i want to return message(@ret) in asp.net label control, but nothing is showing on the label control.
somebody help.
This is my stored procedure:
ALTER procedure dbo.InsertName
@Cname nchar(10),
@Address nchar(10),
@ret varchar(100) output
as
if exists (select * from mytable where Cname=@Cname)
begin
select @ret as [ret]
set @ret='insert failed. Record exists already'
end
else
begin
insert into mytable values (@Cname,@Address)
select @ret as [ret]
set @ret='insert successful'
end
Here is my code behind:
protected void Button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True";
string result="";
SqlConnection conn = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "InsertName";
cmd.Parameters.AddWithValue("@Cname", this.TextBox1.Text);
cmd.Parameters.AddWithValue("@Address", this.TextBox2.Text);
cmd.Parameters.AddWithValue("@ret", result);
cmd.Connection = conn;
cmd.Parameters["@ret"].Direction = ParameterDirection.InputOutput;
conn.Open();
cmd.ExecuteNonQuery();
Label1.Text = result;
It works, but it does not display the message in the label control.
Anybody tell me what i did not do right.