protected void btnHiddenCheckIn_Click(object sender, EventArgs e)
{/ointments();
ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "checkINClick('" + hidPatientName.Value + "');", true);
return;
}
}
}
}
protected void btnHiddenCheckIn_Click(object sender, EventArgs e) {/ointments(); ScriptManager.RegisterStartupScript(this, this.GetType(), starScript, checkINClick(‘ + hidPatientName.Value +
Share
Nikhil,
Declare
SqlTransaction objSqlTransaction;at the top, but don’t initialize it!Where you are setting
objSqlDbCommproperties like Connection, TimeOut etc… You need to pass SqlTransaction object to set toSqlCommand.Transactionproperty!Now where you want to start Transaction initialize the object:
And when you are finished with inserts and updates, may be at the end of else… write
transaction.Commit();, if it was not successful exception will be thrown… So add try catch to your code, declare SqlTransaction before starting try and in catchtransaction.RollBack();See complete example on MSDN:
SqlTransaction
UPDATE:
That is because you are using same SqlCommand object for ExecuteNonQuery and ExecuteDataSet, you need to use different SqlCommand object when ExecuteDataSet… Because your SqlCommand is a part of transaction!