private void Button_Click(object sender, RoutedEventArgs e) { a1 = Name.Text; a2 = SurName.Text; a3 = Phone.Text; a4 = null; a5 = true; Window2 W2 = new Window2(); if ((Name.Text != "") && (SurName.Text != "") && (Phone.Text != "")) { using (SqlConnection connection = new SqlConnection(@"Data Source=desktop-403shtp\igorsql;Initial Catalog=Users;Integrated Security=True;ConnectRetryCount=2;ConnectRetryInterval=3")) { connection.Open(); SqlCommand command = new SqlCommand("INSERT INTO Info (Login, Name, Surname, Phone,InBase) " + "VALUES(@Login, @Name, @Surname, @Phone, @InBase)", connection); command.Parameters.AddWithValue("Login", Loginn); command.Parameters.AddWithValue("Name", a1); command.Parameters.AddWithValue("Surname", a2); command.Parameters.AddWithValue("Phone", a3); command.Parameters.AddWithValue("InBase", a5); MessageBox.Show("Registration is over, Sir"); command.ExecuteNonQuery(); W2.Show(); SqlDataAdapter sda1 = new SqlDataAdapter("Select Name From Info where Login = '******'", connection); DataTable dt1 = new DataTable(); sda1.Fill(dt1); MessageBox.Show(Convert.ToString(dt1)); W2.Name.Text = Convert.ToString(dt1.Rows[0][0]); this.Close(); } } else if (Name.Text == "") { A11.Foreground = Brushes.Red; } else if (SurName.Text == "") { A12.Foreground = Brushes.Red; } else if (Phone.Text == "") { A13.Foreground = Brushes.Red; } }