Hi! I used this code it’s worked. But I want when Id exist then output any parameter equal 1 else 0. because I have two button Add and Continue.
CREATE PROCEDURE InsertName
@Id INT = NULL
@Name VARCHAR(50)= ''
as
BEGIN
IF NOT EXISTS(SELECT Count(Id) FROM ParsonTable WHERE Id = @Id) OR @Id IS NULL
BEGIN
INSERT INTO ParsonTable(FirstName) VALUES(@Name)
SELECT 1
END
ELSE
BEGIN
UPDATE ParsonTable
SET FirstName = @Name
WHERE Id = @Id
SELECT 0
END
END
private void GetData(string name)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "InsertName";
cmd.Parameters.AddWithValue("@Name",
cmd.Connection = con;
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch { }
con.Close();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
GetData(Name.Text);
If (parameter = 0)
{
btnAdd.Enabled = true;
}
else
{
btnContinue.Enabled = true;
}
}