0

I am reading a Textfile which contains Information about Filename, Filepath, Filesize and modified Date.

I am able to select all necessary data and store them successfully in a datatable which I then store it to my SQL Server with Stored Procedure. However, at some point (or row) I am selecting the Filesize-Entry which string is like (333,461) instead of 333,461 , to store this value to my SQL Server I need it to be converted in to float and this value divided by 1000 (Bytes in Kilobytes). My current (shortened) code is:

var Txtfile = File.ReadLines(@"C:\Users\[Path to my File]")
            .Where(s => (s.StartsWith("20") && s.Split(new char[] { ' ' }, 5, StringSplitOptions.RemoveEmptyEntries)[2] != "<DIR>")
            || Regex.Match(s, @"^\s.{1}:.*").Success);

the variable Txtfile is now an array of strings, which 3rd entry is the Filesize. Then I edit this value with:

 (float)(Math.Truncate((Convert.ToDouble(Txtfile[2]) / 1000F)))

This works so far until I meet a value which is in parenthesis "(somevalue)".

So I tried Txtfile[2] = Txtfile[2].Replace("(", "").Replace(")", "");

After running the code, my application is going in break mode and wont do anything, continuing my app results in nothing. Does anyone have a clue what to do?

Exception thrown: Managed Debugging Assistant 'ContextSwitchDeadlock' Enabling it doesn't solve the problem.

I will then get the following exception:

System.Data.SqlClient.SqlException: 'String or binary data would be truncated. The data for table-valued parameter "@MyTableType" doesn't conform to the table type of the parameter. SQL Server error is: 8152, state: 10

That means I cant convert the edited(removed '(' and ')') string to float?

V.Hunon
  • 320
  • 3
  • 12

0 Answers0