I know this is C#, but thought the SQL community would know better. I'm trying to get a CLR compiled to handle a Double.TryParse () via TSQL and the code won't compile.
I'm no C# guru, found this code on the web when looking for a way to try_parse in earlier versions of sql (2005).
The underlined is where my issue is. Here is the error.
Any help on the matter would be appreciated, i'm ready for an easier way to convert varchar to decimal(18,8) and not break on errors to be expected.
Thanks!
I'm no C# guru, found this code on the web when looking for a way to try_parse in earlier versions of sql (2005).
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; namespace ClassLibrary1 { public class Class1 { [SqlFunction] public static SqlDouble TryParseDouble(SqlString str) { Double d; bool success = [U]Double.TryParse(str, out d)[/U]; if (!success) return SqlDouble.Null; return new SqlDouble(d); } } }
Code:
Error 1 The best overloaded method match for 'double.TryParse(string, out double)' has some invalid arguments c:\xxxxx\Class1.cs 16 32 ClassLibrary1 Error 2 Argument 1: cannot convert from 'System.Data.SqlTypes.SqlString' to 'string' c:\xxxxx\Class1.cs 16 48 ClassLibrary1
Thanks!
Comment