I have written procedure for updating country including already exist.
While running the code, if a record is updated it is "showing record updated successfuly" and when another record is updated with the same name in the list record is not updated but the message is showing "record updated successfully". Find the below c# code which I have written
protected void btnSave_Click(object sender, EventArgs e)
{
Country objCountry = new Country();
CountryBAL objCountryBal = new CountryBAL();
objCountry.CountryName = txtCountryName.Text;
objCountry.Status = Convert.ToInt16(ddlStatus.SelectedValue);
if (ViewState["Id"] != null)
{
if (!string.IsNullOrEmpty(ViewState["Id"].ToString()))
{
objCountry.CountryId = Convert.ToInt32(ViewState["Id"]);
bool status = (new CountryBAL().UpdateCountry(objCountry));
if (status == true)
{
BindCountry();
tabErrMess.Visible = true;
lblMessage.Text = "Record Updated Successfully";
txtCountryName.Text = "";
ViewState["Id"] = null;
}
else
{
tabErrMess.Visible = true;
lblMessage.Text = "Updatation Failed";
ImgMsg.Visible = false;
}
}
}
Loading
VulpesPosted Oct 13, 2011, 5:37 PM
It always looks a bit strange to me, though, so I'd tend to use the brackets for clarity.
Sam HobbsPosted Oct 13, 2011, 5:05 PM
is it the same as:
I suppose that the way that syntax is evaluated depends on operator precedence. I don't understand the C# documentation of operator precedence but I assume it says what we expect it to say. I suppose that one cause of my confusion is that C++ syntax is different. So unless any of my comments are relevant to the question for this thread, my comments can be ignored.
keerthiPosted Oct 13, 2011, 6:29 AM
Hemant KumarPosted Oct 13, 2011, 6:18 AM
http://stackoverflow.com/questions/639854/tsql-check-if-a-row-exists-otherwise-insert
http://stackoverflow.com/questions/3189293/check-if-record-exists-update-if-not-insert-stored-procedure
Use if exists to see if the record exists or not:
if exists(select * from yourTable where ID = @id)
Try that.begin
// update your data
update yourTable
set columnOne = @columnOne
where ID = @id
end
else
begin
// insert data
insert into yourTable (@id,@columnOne)
end
VulpesPosted Oct 13, 2011, 6:08 AM