Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TWORZENIE TABELI NADANIE NAZW KOLUMNOWM
- DataTable table = new DataTable("produkt");
- table.Columns.Add("Nazwa", typeof(String));
- table.Columns.Add("Kod", typeof(String));
- table.Columns.Add("Cena", typeof(Double));
- table.Columns.Add("Jednostka", typeof(String));
- table.Columns.Add("Ilosc", typeof(Int32));
- Stream myStream = null;
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- openFileDialog1.InitialDirectory = "c:\\";
- openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- openFileDialog1.FilterIndex = 2;
- openFileDialog1.RestoreDirectory = true;
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- try
- {
- if ((myStream = openFileDialog1.OpenFile()) != null)
- {
- using (myStream)
- {
- //ODCZYTANIE WYBRANEGO PLIKU
- StreamReader reader = new StreamReader(myStream);
- string linia;
- while ((linia = reader.ReadLine()) != null)
- {
- string[] items = linia.Split('\t');
- //UPEWNIENIE SIE DLUGOSCI TABELI
- DataRow row = table.NewRow();
- row["Nazwa"] = items[0];
- row["Kod"] = Int32.Parse(items[1]);
- row["Cena"] = Double.Parse(items[2]);
- row["Jednostka"] = items[3];
- row["Ilosc"] = Int32.Parse(items[1]);
- table.Rows.Add(row);
- }
- reader.Close();
- reader.Dispose();
- }
- gridControl1.DataSource = table;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Blas");
- }
- gridControl1.DataSource = table;
- //WCZYTANIE TABELI DO GRIDA
- table.Dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement