netmajor
netmajor

Reputation: 6585

read text file in sql like in c# - example

How can I translate that c# read text file code to sql ? :

using (StreamReader sr = File.OpenText(FILE_NAME))
        {
            String input = sr.ReadToEnd();
            while (!string.IsNullOrEmpty(input))
            {
                int EndLineIndex = input.IndexOf("<entry>");
                if(EndLineIndex!=-1)
                {
                  string Row = input.Substring(0,EndLineIndex);
                  string[] Data = Row.Split("<delim>");
                  input = input.Remove(0,EndLineIndex+7);
                }
            }

        }

I read csv file where column delimiter is and each row end with . Most inportant is to find sql equivalent of indexOf, substring,split and remove.

Upvotes: 1

Views: 708

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460058

But if you want to import that file into SQL-Server, you could bulk-insert it directly.

BULK INSERT (Transact-SQL)

Upvotes: 2

Related Questions