Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void btnregister_Click(object sender, EventArgs e)
   {
       con.Open();
       {
           cmd.CommandText = "usp_adduser";
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@user_name", txtusername.Text);
           cmd.Parameters.AddWithValue("@password", txtpassword.Text);
           cmd.Parameters.AddWithValue("@firstname", txtfname.Text);
           cmd.Parameters.AddWithValue("@lastname", txtlname.Text);
           cmd.Connection = con;
           cmd.ExecuteNonQuery();
           int check = 0;
           check = cmd.ExecuteNonQuery();
           if (check == 1)
           {
               con.Close();
           }
           else
           {
               Response.Write("Error");
           }
       }
       con.Close();
   }



this is above code.


ALTER PROCEDURE dbo.usp_adduser
--@user_id int = 1,
@user_name varchar(50),
@password varchar(50),
@firstname varchar(50),
@lastname varchar(50)


AS
begin

insert into registeruser (user_name,password,firstname,lastname) values (@user_name,@password,@firstname,@lastname)

end

and the above is the stored procedure..
Posted

you are calling function twice.

use "cmd.ExecuteNonQuery();" once
 
Share this answer
 
this code line should be used once
cmd.ExecuteNonQuery();

for detail read this link http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery(v=vs.110).aspx[^]
 
Share this answer
 

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