SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master"].ConnectionString);
SqlTransaction tran=null ;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;
try
{
con.Open();
tran=con.BeginTransaction();
cmd = new SqlCommand("InserData", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Name", txtName.Text.Trim().Replace("'", "''"));
cmd.Parameters.AddWithValue("dept_id", ddldept.SelectedValue);
cmd.Parameters.AddWithValue("Contact", txtContact.Text.Trim().Replace("'", "''"));
cmd.Transaction = tran;
cmd.ExecuteNonQuery();
tran.Commit();
}
catch
{
tran.Rollback();
con.Close();
}
finally { con.Close(); }
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment