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

Recommended Answers

All 3 Replies

Try using StreamReader.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ReadLines
{
    class Program
    {


        static void Main(string[] args)
        {

            using (StreamWriter _SW = new StreamWriter("File.txt"))
            {
                for (int i = 0; i < 200; i++)
                    _SW.WriteLine("Pre-200 #: " + i);
                for (int i = 0; i < 50; i++)
                    _SW.WriteLine("Post-200 #: " + i);
            }

            using (StreamReader _SR = new StreamReader("File.txt", Encoding.UTF8))
            {
                for(int i = 0; i < 200; i++)
                    Console.WriteLine(_SR.ReadLine());
            }

            Console.WriteLine("\n\n\nPress any key to exit");
            Console.ReadLine();
        }
    }
}

Hrm.. i used that exact code but, i get a text file full of

Pre-200 #: 1

continuously Any other suggestions?

Then you aren't using the exact same code. Because I get the correct output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.