Advertisement
filip710

BAZE PODATAKA LV5 Z1

Dec 21st, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace Baze_LV6_predlozak
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void btnSve_Click(object sender, EventArgs e)
  22.         {
  23.             // OVDJE SLIJEDI PRIMJER IZ PREDLOŠKA:
  24.             SqlConnection conn = new SqlConnection("Data Source=192.168.26.14;Initial Catalog=stuslu;User ID=stuslu;Password=stuslu");
  25.             conn.Open();
  26.             string statement = "SELECT * FROM student";
  27.             SqlDataAdapter dataAdapter = new SqlDataAdapter(statement, conn);
  28.             DataTable dt = new DataTable();
  29.             dataAdapter.Fill(dt);
  30.             dgvPodaci.DataSource = dt;
  31.             conn.Close();
  32.         }
  33.  
  34.         private void btnTrazi_Click(object sender, EventArgs e)
  35.         {
  36.             // OVDJE PISATI KOD 1. ZADATKA IZ PREDLOŠKA:
  37.             char spol;
  38.             if (rbM.Checked)
  39.                 spol = 'M';
  40.             else
  41.                 spol = 'F';
  42.  
  43.             SqlConnection conn = new SqlConnection("Data Source=192.168.26.14;Initial Catalog=stuslu;User ID=stuslu;Password=stuslu");
  44.             conn.Open();
  45.             string statement = "SELECT * FROM student WHERE (ime = '" + txtIme.Text + "' OR prezime = '" + txtPrezime.Text + "') AND spol = '" + spol +"';";
  46.             SqlDataAdapter dataAdapter = new SqlDataAdapter(statement, conn);
  47.             DataTable dt = new DataTable();
  48.             dataAdapter.Fill(dt);
  49.             dgvPodaci.DataSource = dt;
  50.             conn.Close();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement