Reputation: 6585
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
Reputation: 460058
Substring
: SUBSTRINGIndexOf
: CHARINDEXSplit
: SQL-Server uses tables not Arrays, this
is the best reading on this subject.Remove
: use also SUBSTRING)But if you want to import that file into SQL-Server, you could bulk-insert it directly.
Upvotes: 2