Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
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)
  #2 (permalink)  
Old August 31st, 2009, 08:17 AM
Registered User
Join Date: Aug 2009
Location: china
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to 龙腾飞 Send a message via Yahoo to 龙腾飞
Smile 谢谢你


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05: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

All times are GMT -4. The time now is 02:44 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.