using System; using System.Windows.Forms; using System.Drawing; using System.Data.SqlClient; class ex : Form { Label lb1 = new Label(); TextBox tb1 = new TextBox(); Button b1 = new Button(); ex() { Text = "hello"; lb1.Text = "example_label:"; b1.Text = "button"; b1.Click += new EventHandler(button_b1_click); tb1.Location = new Point(100, 0); b1.Location = new Point(200, 0); Controls.Add(lb1); Controls.Add(tb1); 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 @@version", conn); SqlDataReader reader = command.ExecuteReader(); reader.Read(); tb1.Text = reader[0].ToString(); conn.Close(); } static public void Main() { Application.Run(new ex()); } }