Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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. using System.Data.SqlClient;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. static string _con0 = "Data Source=UC202-UCITEL\\SQLEXPRESS;Initial Catalog=Poliklinika;Integrated Security=SSPI";
  16. static SqlConnection _con = new SqlConnection(_con0);
  17. public Form1()
  18. {
  19. InitializeComponent();
  20.  
  21. List<string> jaj;
  22. jaj = Select_Pacient(_con0); // 0a) Select orig
  23. Console.WriteLine("\n0)Orig:");
  24.  
  25. //with_Items_AddRange_DataSource();
  26. //with_Items_Add();
  27. }
  28. void with_Items_AddRange_DataSource()
  29. {
  30. string[] x = new string[4];
  31.  
  32. x[0] = "1";
  33. x[1] = "2";
  34. x[2] = "11";
  35. x[3] = "22";
  36.  
  37. //listBox1.Items.AddRange(x);// by default no item is selected
  38. listBox1.DataSource = x; // by default the first item is selected
  39. }
  40. void with_Items_Add()
  41. {
  42. string[] x = new string[4];
  43.  
  44. x[0] = "1";
  45. x[1] = "2";
  46. x[2] = "11";
  47. x[3] = "22";
  48.  
  49. for (int i = 0; i < x.Length; i++)
  50. listBox1.Items.Add(x[i]); // by default the first item is selected
  51. }
  52. public List<string> Select_Pacient(string con0)
  53. {
  54. SqlConnection con = new SqlConnection(con0);
  55. //string s = "Select CompanyName from Customers";
  56. string s = "Select krstne from pacienti where idP >= 3";
  57. //string s = "Select krstne from lekari where idL >= 3";
  58. //string s = "Select spec from lekari where idL >= 3";
  59. SqlCommand cmd = new SqlCommand(s, con);
  60.  
  61. con.Open();
  62. SqlDataReader read;
  63. read = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  64.  
  65. List<string> x = new List<string>();
  66. while (read.Read())
  67. {
  68. //x.Add(read["krstne"].ToString());
  69. //x.Add(read["spec"].ToString());
  70. listBox1.Items.Add(read["krstne"].ToString());
  71. }
  72.  
  73. con.Close();
  74. return x;
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement