Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 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.IO;
  10. using System.Collections;
  11.  
  12.  
  13. namespace Conversions
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             OpenFileDialog openFileDialog1 = new OpenFileDialog();
  25.  
  26.             openFileDialog1.InitialDirectory = "c:\\";
  27.             openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
  28.             openFileDialog1.FilterIndex = 2;
  29.             openFileDialog1.RestoreDirectory = true;
  30.  
  31.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  32.             {
  33.                 textBox1.Text = openFileDialog1.FileName;
  34.             }
  35.  
  36.  
  37.         }
  38.  
  39.         private void button2_Click(object sender, EventArgs e)
  40.         {
  41.  
  42.             String Delimiter = ",";
  43.             String TableName = "Conversions";
  44.  
  45.             DataSet ds = new DataSet();
  46.             StreamReader sr = new StreamReader(textBox1.Text);
  47.  
  48.                 ds.Tables.Add(TableName);
  49.                 ds.Tables[TableName].Columns.Add("Unit1");
  50.                 ds.Tables[TableName].Columns.Add("Unit2");
  51.                 ds.Tables[TableName].Columns.Add("ConValue");
  52.  
  53.                 string GrabText = sr.ReadToEnd();
  54.  
  55.                 string[] DataRows = GrabText.Split("\r".ToCharArray());
  56.                
  57.  
  58.                 foreach (string r in DataRows)
  59.                 {
  60.                     String[] EachItem = r.Split(Delimiter.ToCharArray());
  61.                     ds.Tables[TableName].Rows.Add(EachItem);
  62.  
  63.                 }
  64.  
  65.                 this.datagrid.DataSource = ds.Tables[0].DefaultView;
  66.             }
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement