void SubmitForm()
{
string IPAddress = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConStr"].ConnectionString.ToString());
SqlTransaction objTran;
if (objCon.State == ConnectionState.Closed)
objCon.Open();
objTran = objCon.BeginTransaction();
try
{
new SqlCommand("insert into tblSampleTest(name) values ('Pabitra Microsoft Research');", objCon, objTran).ExecuteNonQuery();
new SqlCommand("insert into tblSampleTestLog (name,EntryDate,IPAddress) values ('Pabitra Microsoft Research',getdate(),'"+IPAddress+"');", objCon, objTran).ExecuteNonQuery();
objTran.Commit();
}
catch (SqlException SqlEx)
{
objTran.Rollback();
throw (SqlEx);
}
catch (Exception ex)
{
throw(ex);
}
finally
{
objCon.Close();
}
{
string IPAddress = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConStr"].ConnectionString.ToString());
SqlTransaction objTran;
if (objCon.State == ConnectionState.Closed)
objCon.Open();
objTran = objCon.BeginTransaction();
try
{
new SqlCommand("insert into tblSampleTest(name) values ('Pabitra Microsoft Research');", objCon, objTran).ExecuteNonQuery();
new SqlCommand("insert into tblSampleTestLog (name,EntryDate,IPAddress) values ('Pabitra Microsoft Research',getdate(),'"+IPAddress+"');", objCon, objTran).ExecuteNonQuery();
objTran.Commit();
}
catch (SqlException SqlEx)
{
objTran.Rollback();
throw (SqlEx);
}
catch (Exception ex)
{
throw(ex);
}
finally
{
objCon.Close();
}
}
No comments:
Post a Comment