0% found this document useful (0 votes)
24 views

Using System

The document contains code for adding branch information to a database table. It opens a SQL connection and transaction. It inserts values from textboxes and dropdownlists on the form into the BranchInfo table. If an error occurs, the transaction is rolled back. The connection is closed and the page is redirected upon successful insert.

Uploaded by

Hasnain Ansari
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Using System

The document contains code for adding branch information to a database table. It opens a SQL connection and transaction. It inserts values from textboxes and dropdownlists on the form into the BranchInfo table. If an error occurs, the transaction is rolled back. The connection is closed and the page is redirected upon successful insert.

Uploaded by

Hasnain Ansari
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using using using using using using using using using

System; System.Collections; System.Configuration; System.Data; System.Linq; System.Web; System.Web.Security; System; System.Data.SqlClient;

public partial class InsAdmin_Admin_images_Add_Branch_2 : System.Web.UI.Page { SqlConnection con = new SqlConnection(); SqlCommand cmd = new SqlCommand(); protected void Page_Load(object sender, EventArgs e) { Session["Login Name"] = User.Identity.Name; con.ConnectionString = DBConnection.GetConnection(); cmd.Connection = con; } protected void Button1_Click(object sender, EventArgs e) { SqlTransaction Trans = null; try { con.Open(); Trans =con.BeginTransaction(); cmd.Transaction=Trans; cmd.CommandText="insert into BranchInfo(BranchCode,BranchName,Address,ContactNo1,ContactNo2,EmailID,Timezo neID,Currency)values(@BranchCode,@BranchName,@Address,@ContactNo1,@ContactNo2 ,@EmailID,@TimezoneID,@Currency)"; cmd.Parameters.AddWithValue("@BranchCode",TextBox1.Text); cmd.Parameters.AddWithValue("@BranchName",TextBox2.Text); cmd.Parameters.AddWithValue("@Address",TextBox3.Text); cmd.Parameters.AddWithValue("@ContactNo1",TextBox4.Text); cmd.Parameters.AddWithValue("@ContactNo2",TextBox5.Text); cmd.Parameters.AddWithValue("@EmailID",TextBox6.Text); cmd.Parameters.AddWithValue("@TimezoneID",DropDownList1.SelectedValue.ToStrin g()); cmd.Parameters.AddWithValue("@Currency",DropDownList2.SelectedValue.ToString( )); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); } catch { Trans.Rollback(); } finally { con.Close(); } Response.Redirect("HomePage.aspx");

} }

You might also like