I'm reading a text file and inserting it into database, using following code, which contains few strings like this
DAV|FIN-ABC;0;0;363.03;|*
DAV|SIN-CTF;0;0;299.46;|*
DAV|POS-PTF;100;135;299.46;|*
DAV|DON-ATF;200;150;363.03;|*
DAV|DSS-ATF;100;135;297.46;|*
All the values are inserted into table, problem is first column which is separated by 'pipe separator'. [FONT='Verdana','sans-serif']
Can anyone amend the following code with liffle effort to separate first column with pipe and than others with semi colon which is working but problem is to separate first column with pipe separator. [/FONT]
Code:
[FONT='Verdana','sans-serif']using
System;
using
System.IO;
using
System.Collections.Generic;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
namespace
Reading_File
{
class ReadingFile
{
static void Main(string[] args)
{
string str = string.Empty;
string[] storage = null;
string strClientBates = string.Empty;
string strFilePath = string.Empty;
char[] pipe ={ '|' };
char[] semi ={ ';' };
// string record_identifier;
/* Variables to store values of Text FileTemporarily */
string etf_symbol;
string volume_traded;
string etf_last_traded_price;
string nav;
/* Reading Text File for the values */
using (FileStream file = new FileStream("Text.txt", FileMode.Open, FileAccess.ReadWrite))
{
using (StreamReader reader = new StreamReader(file))
{
while ((str = reader.ReadLine()) != null)
{
/* Separating values with 'semi-colon separator */
storage = str.Split(semi);
if (storage != null)
{
etf_symbol = storage[0];
volume_traded = storage[1];
etf_last_traded_price = storage[2];
nav = storage[3];
/* Opening Connection */
string sConn = "server=AHIML-SRV-GAPP; uid=invest513; pwd=dar!197^4; database=ahi; Connect Timeout=10000";
SqlConnection ObjCon = new SqlConnection(sConn);
/* Inserting values into Table */
string sQuery = "Insert into etf values('','" + etf_symbol + "','" + volume_traded + "','" + etf_last_traded_price + "','" + nav + "')";
SqlCommand ObjCmd = new SqlCommand(sQuery, ObjCon);
ObjCon.Open();
int a = ObjCmd.ExecuteNonQuery();
ObjCon.Close();
Console.WriteLine("Records inserted successfully");
}
}
}
}
}
}
}
[/FONT]