my table is like this
create table tbl_user
(
userID int Primary Key identity (1,1),
userName varchar(20),
pass varchar(30),
email varchar(50),
userRole int,
userPhoto varchar(100),
userStatus int,
);
create PROCEDURE spCreateUser
@userName varchar(20),
@pass varchar(30),
@email varchar(50),
@userRole int,
@userPhoto varchar(100),
@userStatus int,
@result int output
AS
BEGIN
IF EXISTS(SELECT * FROM tbl_user WHERE userName= @userName)
SET @result = 1
ELSE
BEGIN
SET @result = 0
INSERT INTO tbl_user(userName,pass,email,userRole,userPhoto,userStatus)
VALUES(@userName,@pass,@email,@userRole,@userPhoto,@userStatus)
END
return @result
END
asp.net c# code like this
protected void btn_insert_Click(object sender, EventArgs e)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
string path = string.Concat(Server.MapPath("~/UploadFile/" + fu_photo.FileName));
fu_photo.SaveAs(path);
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spCreateUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("userName", txt_username.Text);
cmd.Parameters.AddWithValue("pass", txt_pass.Text);
cmd.Parameters.AddWithValue("email", txt_email.Text);
cmd.Parameters.AddWithValue("userRole", ddl_role.SelectedValue);
cmd.Parameters.AddWithValue("userPhoto", path);
cmd.Parameters.AddWithValue("userStatus", ddl_status.SelectedValue);
con.Open();
int k = cmd.ExecuteNonQuery();
if (k != 0)
{
lblMsg.Text = "Record Inserted Succesfully into the Database";
lblMsg.ForeColor = System.Drawing.Color.CornflowerBlue;
}
con.Close();
}
}
What I have tried:
i would like to save unique username and password in table using storeprocedture please also tell update opration too. how i use this sp with in my code.
Thanks