vakho

ADO.NET

Oct 11th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. using System.Data.SqlClient;
  11.  
  12. namespace TestApp
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         SqlConnection connection;
  17.         SqlCommand command;
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void buttonSearch_Click(object sender, EventArgs e)
  25.         {
  26.             StringBuilder str = new StringBuilder();
  27.             SqlDataReader reader = command.ExecuteReader();
  28.             while (reader.Read())
  29.             {
  30.                 str.Append(reader["Name"]);
  31.                 str.Append(reader["Surname"]);
  32.                 str.Append(reader["BirthDay"]);
  33.             }
  34.             MessageBox.Show(str.ToString());
  35.             reader.Close();
  36.         }
  37.  
  38.         private void Form1_Load(object sender, EventArgs e)
  39.         {
  40.             connection = new SqlConnection();
  41.             connection.ConnectionString = "Server=LAB-418-11-PC\\STUDENT; database=Test_DB; Integrated Security=true;";
  42.             connection.Open();
  43.             MessageBox.Show(connection.State.ToString(), "State Of Connection");
  44.  
  45.             command = new SqlCommand();
  46.             command.Connection = connection;
  47.             command.CommandText = "SELECT * FROM Students WHERE Surname like '%" + textSearch.Text + "%'";
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment