D
DB161998
Guest
I am new to C# and Visual Studio. I am currently stuck on a problem in developing code to push a tab delimited text file into a DataTable. As of now the code pulls the txt. file from my laptop reads all the lines and gives me two results based on the conditions within the code. Now that I have completed that I am hoping to push the full txt. file into a datatable to use for later purposes. If somebody is able to help clarify any of my errors I would greatly appreciate it. I am posting the code below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Data;
namespace ConsoleApp66
{
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Rexel\Test.txt";
List<string> Amount = File.ReadAllLines(filePath).ToList();
string[] row;
foreach (string line in Amount)
{
row = line.Split('\t');
if (Convert.ToDecimal(row[12]) > 0 && Convert.ToDecimal(row[12]) < 25000)
{
Console.WriteLine("Payment Amount: " + row[12]);
Console.WriteLine("Status: Ready to Send");
}
else if (Convert.ToDecimal(row[12]) >= 25000)
{
Console.WriteLine("Payment Amount: " + row[12]);
Console.WriteLine("Status: Needs Approval");
}
public DataTable ConvertToDataTable(int numberOfColumns, string filePath1)
{
DataTable tbl = new DataTable();
for (int col = 0; col < numberOfColumns; col++)
tbl.Columns.Add(new DataColumn("Column" + (col + 1).ToString()));
string[] lines = System.IO.File.ReadAllLines(filePath1);
foreach (string line1 in lines)
{
var cols = line1.Split(':');
DataRow dr = tbl.NewRow();
for (int cIndex = 0; cIndex < 3; cIndex++)
{
dr[cIndex] = cols[cIndex];
}
tbl.Rows.Add(dr);
}
return tbl;
}
}
}
}
}
Continue reading...
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Data;
namespace ConsoleApp66
{
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Rexel\Test.txt";
List<string> Amount = File.ReadAllLines(filePath).ToList();
string[] row;
foreach (string line in Amount)
{
row = line.Split('\t');
if (Convert.ToDecimal(row[12]) > 0 && Convert.ToDecimal(row[12]) < 25000)
{
Console.WriteLine("Payment Amount: " + row[12]);
Console.WriteLine("Status: Ready to Send");
}
else if (Convert.ToDecimal(row[12]) >= 25000)
{
Console.WriteLine("Payment Amount: " + row[12]);
Console.WriteLine("Status: Needs Approval");
}
public DataTable ConvertToDataTable(int numberOfColumns, string filePath1)
{
DataTable tbl = new DataTable();
for (int col = 0; col < numberOfColumns; col++)
tbl.Columns.Add(new DataColumn("Column" + (col + 1).ToString()));
string[] lines = System.IO.File.ReadAllLines(filePath1);
foreach (string line1 in lines)
{
var cols = line1.Split(':');
DataRow dr = tbl.NewRow();
for (int cIndex = 0; cIndex < 3; cIndex++)
{
dr[cIndex] = cols[cIndex];
}
tbl.Rows.Add(dr);
}
return tbl;
}
}
}
}
}
Continue reading...