Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. //TWORZENIE TABELI NADANIE NAZW KOLUMNOWM
  2. DataTable table = new DataTable("produkt");
  3. table.Columns.Add("Nazwa", typeof(String));
  4. table.Columns.Add("Kod", typeof(String));
  5. table.Columns.Add("Cena", typeof(Double));
  6. table.Columns.Add("Jednostka", typeof(String));
  7. table.Columns.Add("Ilosc", typeof(Int32));
  8. Stream myStream = null;
  9. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  10.  
  11. openFileDialog1.InitialDirectory = "c:\\";
  12. openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
  13. openFileDialog1.FilterIndex = 2;
  14. openFileDialog1.RestoreDirectory = true;
  15.  
  16. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  17. {
  18. try
  19. {
  20. if ((myStream = openFileDialog1.OpenFile()) != null)
  21. {
  22. using (myStream)
  23. {
  24. //ODCZYTANIE WYBRANEGO PLIKU
  25. StreamReader reader = new StreamReader(myStream);
  26.  
  27. string linia;
  28.  
  29. while ((linia = reader.ReadLine()) != null)
  30. {
  31. string[] items = linia.Split('\t');
  32. //UPEWNIENIE SIE DLUGOSCI TABELI
  33.  
  34. DataRow row = table.NewRow();
  35. row["Nazwa"] = items[0];
  36. row["Kod"] = Int32.Parse(items[1]);
  37. row["Cena"] = Double.Parse(items[2]);
  38. row["Jednostka"] = items[3];
  39. row["Ilosc"] = Int32.Parse(items[1]);
  40.  
  41. table.Rows.Add(row);
  42.  
  43. }
  44. reader.Close();
  45. reader.Dispose();
  46.  
  47. }
  48. gridControl1.DataSource = table;
  49.  
  50. }
  51.  
  52. }
  53. catch (Exception ex)
  54. {
  55. MessageBox.Show("Blas");
  56. }
  57.  
  58. gridControl1.DataSource = table;
  59. //WCZYTANIE TABELI DO GRIDA
  60.  
  61. table.Dispose();
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement