Importing txt into SQL line skip

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a c# application which imports the txt log files into SQL database. There are some lines which start with hash(#). I want to skip these lines during the binding. You can see hashed lines below.#Software: Microsoft Internet Information Services 7.5
#Version: 1.0
#Date: 2013-04-02 00:02:27
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2013-04-02 00:02:27 172.16.200.35 GET / - 80 - 172.16.254.18 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+NSM) 401 2 5 0
2013-04-02 00:02:27 172.16.200.35 GET / - 80 MZSGCHAdministrator 172.16.254.18 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+NSM) 200 0 0 62

The last two lines of the code block above are my history lines. The aim is importing them without the hashed lines.
My code is below. What do u suggest me? Thanks in advance.foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourcePath.Length);

String[] allLines = File.ReadAllLines(currentFile);
Directory.Move(currentFile, Path.Combine(targetPath, fileName));

{

for (int i = 0; i < allLines.Length; i++)
{
string[] items = allLines.Split(new char[] { });
nonqueryCommand.Parameters["@column1"].Value = items[0];
nonqueryCommand.Parameters["@column2"].Value = items[1];
nonqueryCommand.Parameters["@column3"].Value = items[2];
nonqueryCommand.Parameters["@column4"].Value = items[3];
nonqueryCommand.Parameters["@column5"].Value = items[4];
nonqueryCommand.Parameters["@column6"].Value = items[5];
nonqueryCommand.Parameters["@column7"].Value = items[6];
nonqueryCommand.Parameters["@column8"].Value = items[7];
nonqueryCommand.Parameters["@column9"].Value = items[8];
nonqueryCommand.Parameters["@column10"].Value = items[9];
nonqueryCommand.Parameters["@column11"].Value = items[10];
nonqueryCommand.Parameters["@column12"].Value = items[11];
nonqueryCommand.Parameters["@column13"].Value = items[12];
nonqueryCommand.Parameters["@column14"].Value = items[13];
//nonqueryCommand.Parameters["@column15"].Value = items[14];
nonqueryCommand.ExecuteNonQuery();
}

}
}

KAdir

View the full article
 
Back
Top