using System; using System.Windows.Forms; using System.Drawing; using System.Data.SqlClient; class ex : Form { 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(); ex() { Text = "Customer entry"; lb1.Text = "CustomerID:"; lb2.Text = "First Name:"; lb3.Text = "Last Name:"; lb2.Location = new Point(0, 25); lb3.Location = new Point(0, 50); Controls.Add(lb1); Controls.Add(lb2); Controls.Add(lb3); tb1.Location = new Point(100, 0); tb2.Location = new Point(100, 25); tb3.Location = new Point(100, 50); Controls.Add(tb1); Controls.Add(tb2); Controls.Add(tb3); b1.Text = "return"; b1.Click += new EventHandler(button_b1_click); b1.Location = new Point(200, 0); Controls.Add(b1); } 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 CustomerID, FirstName, LastName " + "from Customers " + "where CustomerID = 3", conn); SqlDataReader reader = command.ExecuteReader(); reader.Read(); tb1.Text = reader[0].ToString(); tb2.Text = reader[1].ToString(); tb3.Text = reader[2].ToString(); conn.Close(); } static public void Main() { Application.Run(new ex()); } }