Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Configuration;
- using System.Data.SqlClient;
- namespace DataBase {
- public partial class Form1 : Form {
- public Form1() {
- InitializeComponent();
- listBoxId.Items.Add("Id");
- listBoxMaterial.Items.Add("Материал изготовления");
- listBoxYear.Items.Add("Год строительства");
- listBoxCount.Items.Add("Количество этажей");
- string ConnectionString = @"Data Source=.\SQLEXPRESS; Initial Catalog = Houses; Integrated Security = True";
- string SQLExpression = "SELECT * FROM Houses";
- using (SqlConnection connection = new SqlConnection(ConnectionString)) {
- connection.Open();
- SqlCommand command = new SqlCommand(SQLExpression, connection);
- SqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows) { //Если есть данные
- while (reader.Read()) { //Ввод данных в боксы
- listBoxId.Items.Add(reader.GetValue(0));
- listBoxMaterial.Items.Add(reader.GetValue(1));
- listBoxYear.Items.Add(reader.GetValue(2));
- listBoxCount.Items.Add(reader.GetValue(3));
- }
- }
- }
- }
- private void button1_Click(object sender, EventArgs e) {
- string ConnectionString = @"Data Source=.\SQLEXPRESS; Initial Catalog = Houses; Integrated Security = True";
- string SQLExpression = "SELECT * FROM Houses WHERE ([Количество этажей] > 9 AND Материал = 'Кирпич')";
- listBox1.Items.Clear();
- using (SqlConnection connection = new SqlConnection(ConnectionString)) {
- connection.Open();
- SqlCommand command = new SqlCommand(SQLExpression, connection);
- SqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows) { //Если есть данные
- while (reader.Read()) { //Ввод данных в боксы
- listBox1.Items.Add($"Id: {reader.GetValue(0)}, {reader.GetValue(1)}, {reader.GetValue(2)}г., этажей: {reader.GetValue(3)}");
- }
- }
- }
- }
- private void button2_Click(object sender, EventArgs e) {
- string ConnectionString = @"Data Source=.\SQLEXPRESS; Initial Catalog = Houses; Integrated Security = True";
- string SQLExpression = "SELECT * FROM Houses WHERE ([Год строительства] < 1992 AND Материал = 'Панель')";
- listBox1.Items.Clear();
- using (SqlConnection connection = new SqlConnection(ConnectionString)) {
- connection.Open();
- SqlCommand command = new SqlCommand(SQLExpression, connection);
- SqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows) { //Если есть данные
- while (reader.Read()) { //Ввод данных в боксы
- listBox1.Items.Add($"Id: {reader.GetValue(0)}, {reader.GetValue(1)}, {reader.GetValue(2)}г., этажей: {reader.GetValue(3)}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement