943,865 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1751
  • C# RSS
Nov 21st, 2007
0

Read certain # of lines

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
SiPexTBC is offline Offline
28 posts
since Sep 2007
Nov 21st, 2007
0

Re: Read certain # of lines

Try using StreamReader.

C# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 11
Solved Threads: 17
Junior Poster
mariocatch is offline Offline
103 posts
since Apr 2007
Nov 21st, 2007
0

Re: Read certain # of lines

Hrm.. i used that exact code but, i get a text file full of
Quote ...
Pre-200 #: 1
continuously Any other suggestions?
Reputation Points: 10
Solved Threads: 0
Light Poster
SiPexTBC is offline Offline
28 posts
since Sep 2007
Nov 21st, 2007
0

Re: Read certain # of lines

Then you aren't using the exact same code. Because I get the correct output.
Reputation Points: 11
Solved Threads: 17
Junior Poster
mariocatch is offline Offline
103 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Concatination in StringBuilder
Next Thread in C# Forum Timeline: Question about a program I wrote?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC