C# is kicking my butt... I have a text file I'm splitting in hopes to insert into SQL. I need a swift shove in the right direction!
An excerpt from the file I am capturing is below and I am splitting on " - "
2020-06-25-13.23.04.220000 - Running MRP for Site
I can split the two parts just fine. console_output
But can't seem to get the date into a format that is valid for my SQL insert. I think, but could be completely wrong that I need to reformat this date string using some REPLACE commands. If I try and use DateTime.ParseExact using my non-working code below I receive a System.FormatException:String was not recognized as valid on my DateTime.ParseExact line.
foreach (string line in lines)
{
if (line.Contains("Running MRP for Site"))
{
List<string> s = new List<string>(
line.Split(new string[] { " - " }, StringSplitOptions.None));
Console.WriteLine(s[0].ToString());
Console.WriteLine(s[1].ToString());
string format = "yyyy-MM-dd-hh:mm:ss:ffffff";
string date = s[0].ToString().Replace('.', ':');
DateTime dt = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
/*
if (conn.State != ConnectionState.Open)
{
conn = new SqlConnection { ConnectionString = Properties.Settings.Default.ConnectionString };
conn.Open();
}
{
String query = @"INSERT INTO