Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 19th, 2009, 02:32 AM
Registered User
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default Reading Strings from Text File problem

I'm reading a text file and inserting it into database, using following code, which contains few strings like this


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]

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); 
int a = ObjCmd.ExecuteNonQuery(); 
Console.WriteLine("Records inserted successfully"); 
The Following User Says Thank You to gian.sobhani For This Useful Post:
龙腾飞 (August 31st, 2009)
Old August 31st, 2009, 08:17 AM
Registered User
Join Date: Aug 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to 龙腾飞 Send a message via Yahoo to 龙腾飞
Smile 谢谢你


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text file from Resource folder balesh.mind ASP.NET 3.5 Basics 1 November 14th, 2008 06:54 AM
Reading from a Text file for Login and Password.. zabzoub1 Pro Visual Basic 2005 2 July 4th, 2007 01:03 PM
Reading a Text File gmoney060 Classic ASP Basics 2 October 30th, 2004 01:43 AM
reading text file Regornil JSP Basics 2 October 27th, 2004 02:02 AM
Reading from a text file and writing to a Binary 1 scott01 C++ Programming 0 July 28th, 2003 03:59 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.