Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Collections;
- namespace Conversions
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- 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)
- {
- textBox1.Text = openFileDialog1.FileName;
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- String Delimiter = ",";
- String TableName = "Conversions";
- DataSet ds = new DataSet();
- StreamReader sr = new StreamReader(textBox1.Text);
- ds.Tables.Add(TableName);
- ds.Tables[TableName].Columns.Add("Unit1");
- ds.Tables[TableName].Columns.Add("Unit2");
- ds.Tables[TableName].Columns.Add("ConValue");
- string GrabText = sr.ReadToEnd();
- string[] DataRows = GrabText.Split("\r".ToCharArray());
- foreach (string r in DataRows)
- {
- String[] EachItem = r.Split(Delimiter.ToCharArray());
- ds.Tables[TableName].Rows.Add(EachItem);
- }
- this.datagrid.DataSource = ds.Tables[0].DefaultView;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement