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.Windows.Forms;
- using System.Data.SqlClient;
- namespace TestApp
- {
- public partial class Form1 : Form
- {
- SqlConnection connection;
- SqlCommand command;
- public Form1()
- {
- InitializeComponent();
- }
- private void buttonSearch_Click(object sender, EventArgs e)
- {
- StringBuilder str = new StringBuilder();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- str.Append(reader["Name"]);
- str.Append(reader["Surname"]);
- str.Append(reader["BirthDay"]);
- }
- MessageBox.Show(str.ToString());
- reader.Close();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- connection = new SqlConnection();
- connection.ConnectionString = "Server=LAB-418-11-PC\\STUDENT; database=Test_DB; Integrated Security=true;";
- connection.Open();
- MessageBox.Show(connection.State.ToString(), "State Of Connection");
- command = new SqlCommand();
- command.Connection = connection;
- command.CommandText = "SELECT * FROM Students WHERE Surname like '%" + textSearch.Text + "%'";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment