Read certain # of lines

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 28
Reputation: SiPexTBC is an unknown quantity at this point 
Solved Threads: 0
SiPexTBC SiPexTBC is offline Offline
Light Poster

Read certain # of lines

 
0
  #1
Nov 21st, 2007
I have a program that reads an sql file and then executes it into the mysql database. The problem is that when a file larger than 1 mb is executed, an error comes up saying the file is too large. Is there anyway that i can read, say 200 lines of the file, and execute that?

Any help would be appreciated

SiPex
Last edited by SiPexTBC; Nov 21st, 2007 at 8:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 103
Reputation: mariocatch is an unknown quantity at this point 
Solved Threads: 17
mariocatch mariocatch is offline Offline
Junior Poster

Re: Read certain # of lines

 
0
  #2
Nov 21st, 2007
Try using StreamReader.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5.  
  6. namespace ReadLines
  7. {
  8. class Program
  9. {
  10.  
  11.  
  12. static void Main(string[] args)
  13. {
  14.  
  15. using (StreamWriter _SW = new StreamWriter("File.txt"))
  16. {
  17. for (int i = 0; i < 200; i++)
  18. _SW.WriteLine("Pre-200 #: " + i);
  19. for (int i = 0; i < 50; i++)
  20. _SW.WriteLine("Post-200 #: " + i);
  21. }
  22.  
  23. using (StreamReader _SR = new StreamReader("File.txt", Encoding.UTF8))
  24. {
  25. for(int i = 0; i < 200; i++)
  26. Console.WriteLine(_SR.ReadLine());
  27. }
  28.  
  29. Console.WriteLine("\n\n\nPress any key to exit");
  30. Console.ReadLine();
  31. }
  32. }
  33. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 28
Reputation: SiPexTBC is an unknown quantity at this point 
Solved Threads: 0
SiPexTBC SiPexTBC is offline Offline
Light Poster

Re: Read certain # of lines

 
0
  #3
Nov 21st, 2007
Hrm.. i used that exact code but, i get a text file full of
Pre-200 #: 1
continuously Any other suggestions?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 103
Reputation: mariocatch is an unknown quantity at this point 
Solved Threads: 17
mariocatch mariocatch is offline Offline
Junior Poster

Re: Read certain # of lines

 
0
  #4
Nov 21st, 2007
Then you aren't using the exact same code. Because I get the correct output.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC