Hey Friends,
I'm trying to store values in database in stored procedure, but neither they are going in the database nor they are getting stored.
This is my stored procedure:-
ALTER proc [dbo].[cards]
(
@comname varchar(100),
@commes varchar(100),
@job varchar(50),
@name varchar(200),
@add1 varchar(200),
@add2 varchar(200),
@add3 varchar(200),
@phone varchar(10),
@fax varchar(100),
@email varchar(100)
)
as
begin
insert into card1 (comname,commes,job,name,add1,add2,add3,phone,fax,email)
values (@comname,@commes,@job,@name,@add1,@add2,@add3,@phone,@fax,@email)
end
And this is my C#:-
protected void Button1_Click(object sender, EventArgs e)
{
string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS; initial catalog=new; integrated security=true";
SqlConnection con = new SqlConnection(str);
con.Open();
try
{
if (IsPostBack != true)
{
SqlCommand cmd = new SqlCommand("cards", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(Text11.Value.Trim());
cmd.Parameters.Add(Text12.Value.Trim());
cmd.Parameters.Add(Text13.Value.Trim());
cmd.Parameters.Add(Text14.Value.Trim());
cmd.Parameters.Add(Text15.Value.Trim());
cmd.Parameters.Add(Text16.Value.Trim());
cmd.Parameters.Add(Text17.Value.Trim());
cmd.Parameters.Add(Text18.Value.Trim());
cmd.Parameters.Add(Text19.Value.Trim());
cmd.Parameters.Add(Text20.Value.Trim());
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong");
}
finally
{
con.Close();
con.Dispose();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Data Inserted Successfully')", true);
}
}
Another problem is whenever I refresh the page it shows the message "Data Inserted Successfully". PLEASE HELP!!