using System; using System.Windows.Forms; using System.Drawing; using System.Data.SqlClient; class ex : Form { TabControl tc = new TabControl(); TabPage tp1 = new TabPage(); TabPage tp2 = new TabPage(); Label lb1 = new Label(); Label lb2 = new Label(); Label lb3 = new Label(); TextBox tb1 = new TextBox(); TextBox tb2 = new TextBox(); TextBox tb3 = new TextBox(); Button b1 = new Button(); Label lb4 = new Label(); Label lb5 = new Label(); Label lb6 = new Label(); TextBox tb4 = new TextBox(); TextBox tb5 = new TextBox(); TextBox tb6 = new TextBox(); Button b2 = new Button(); ex() { Text = "Customer Tool"; Controls.Add(tc); tc.Dock = DockStyle.Fill; tp1.Text = "Lookup"; tc.TabPages.Add(tp1); lb1.Text = "CustomerID:"; lb2.Text = "First Name:"; lb3.Text = "Last Name:"; lb2.Location = new Point(0, 25); lb3.Location = new Point(0, 50); tp1.Controls.Add(lb1); tp1.Controls.Add(lb2); tp1.Controls.Add(lb3); tb1.Location = new Point(100, 0); tb2.Location = new Point(100, 25); tb3.Location = new Point(100, 50); tp1.Controls.Add(tb1); tp1.Controls.Add(tb2); tp1.Controls.Add(tb3); b1.Text = "Lookup"; b1.Click += new EventHandler(button_b1_click); b1.Location = new Point(200, 0); tp1.Controls.Add(b1); tp2.Text = "Add"; tc.TabPages.Add(tp2); lb4.Text = "CustomerID:"; lb5.Text = "First Name:"; lb6.Text = "Last Name:"; lb5.Location = new Point(0, 25); lb6.Location = new Point(0, 50); tp2.Controls.Add(lb4); tp2.Controls.Add(lb5); tp2.Controls.Add(lb6); tb4.Location = new Point(100, 0); tb5.Location = new Point(100, 25); tb6.Location = new Point(100, 50); tp2.Controls.Add(tb4); tp2.Controls.Add(tb5); tp2.Controls.Add(tb6); b2.Text = "Add"; b2.Click += new EventHandler(button_b2_click); b2.Location = new Point(200, 0); tp2.Controls.Add(b2); } void button_b1_click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source = (localdb)\\sql;" + "User id= sample_user;" + "Password = 'abc'; " + "Database = ex;"); conn.Open(); SqlCommand command = new SqlCommand( "select FirstName, LastName " + "from Customers " + "where CustomerID = @0", conn); command.Parameters.Add(new SqlParameter("0", tb1.Text)); SqlDataReader reader = command.ExecuteReader(); reader.Read(); tb2.Text = reader[0].ToString(); tb3.Text = reader[1].ToString(); conn.Close(); } void button_b2_click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source = (localdb)\\sql;" + "User id= sample_user;" + "Password = 'abc'; " + "Database = ex;"); conn.Open(); SqlCommand command = new SqlCommand("INSERT INTO CUSTOMERS" + "(CustomerID, FirstName, LastName) VALUES (@0, @1, @2)", conn); command.Parameters.Add(new SqlParameter("0", tb4.Text)); command.Parameters.Add(new SqlParameter("1", tb5.Text)); command.Parameters.Add(new SqlParameter("2", tb6.Text)); command.ExecuteNonQuery(); conn.Close(); tb4.Text = ""; tb5.Text = ""; tb6.Text = ""; } static public void Main() { Application.Run(new ex()); } }