Hi Priya,
Please refer below code:
SQL
CREATE PROCEDURE GetExistingRegID
AS
BEGIN
IF EXISTS(SELECT RegistrationID FROM #Temp)
BEGIN
SELECT 'Exist' -- RegistrationID Exist
END
ELSE
BEGIN
SELECT 'NotExist' -- RegistrationID does not exists
END
END
In above code we created procedure through which we get the existing RegistrationID
SQL
CREATE PROCEDURE UpdateRegistrationID
@OldRegID NVARCHAR(200)
,@NewRegID NVARCHAR(200)
AS
BEGIN
UPDATE #Temp
SET RegistrationID = @NewRegID
WHERE RegistrationID = @OldRegID
END
In above code we created procedure through which we update the Old RegistrationID with New RegistrationID
C#
protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
conn.Open();
SqlCommand cmd1 = new SqlCommand("GetExistingRegID", conn);
string exist = cmd1.ExecuteScalar().ToString();
if (exist.ToLower() == "exist")
{
SqlCommand cmd = new SqlCommand("UpdateRegistrtaionID", conn);
cmd.Parameters.AddWithValue("@OldRegID", txtOldRegID.Text);
cmd.Parameters.AddWithValue("@NewRegID", txtNewRegID.Text);
cmd.ExecuteNonQuery();
}
else
{
Response.Write("Please enter your old registrationID Correctly");
}
conn.Close();
}
In above code its checking if Registration ID is Old then it gets replaced with new Registration ID or it will throw error message