Now i need to get that data save into SQL database table(table name=DataDB)...how i can make it?
thanks in advance
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;
namespace myTextReader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpenFile_Click(object sender, EventArgs e)
{
try
{
openFileDialog1.InitialDirectory = txtOpenFile.Text.Trim();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtOpenFile.Text = openFileDialog1.FileName.Trim();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
}
private void btnImport_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtOpenFile.Text.Trim()))
{
MessageBox.Show("Please select file");
return;
}
System.IO.StreamReader sr = new System.IO.StreamReader(txtOpenFile.Text.Trim());
string inputLine = "";
DataTable dt = new DataTable();
dt.Columns.Add("Barcode");
dt.Columns.Add("Price");
dt.Columns.Add("QTY");
dt.Columns.Add("Location");
dt.Columns.Add("Pallet");
dt.Columns.Add("UserID");
dt.Columns.Add("Document");
DataRow row;
while ((inputLine = sr.ReadLine()) != null)
{
string[] array;
array = inputLine.Split(',');
row = dt.NewRow();
row["Barcode"] = array[0];
row["Price"] = array[1];
row["QTY"] = array[2];
row["Location"] = array[3];
row["Pallet"] = array[4];
row["UserID"] = array[5];
row["Document"] = array[6];
dt.Rows.Add(row);
}
dt.Rows.RemoveAt(0);
dataGridView1.DataSource = dt;
sr.Close();
}
catch (Exception)
{
throw;
}
}
This post has been edited by eclipsed4utoo: 02 August 2010 - 04:56 AM
Reason for edit:: the code tags are [code] your code here [/code]

New Topic/Question
Reply




MultiQuote




|