简体   繁体   中英

c# string to sqlstring losing format

I have a SQL CLR function that receives a SQLString, and I am converting the Sql string to ac# string with .ToString() , then after some computing I want to return a sring that contains doubles

   [Microsoft.SqlServer.Server.SqlFunction]
   public static string FuncCS(SqlString SQLstr){
   string CSstr = SQLstr.ToString();

     /*DO SOME STUFF*/
    for (int j = 0; j < S.ColumnCount; j++){
        for (int i = 0; i < S.RowCount; i++){
            CSstr += S[i, j].ToString("F5") + " ,  \t"; 
        }           
    }
  }

Then in SQL I receive a string but the doubles lose their decimal point and is substituted by a misplaced comma:

RESULT:

149,50625 0,00000 0,00000 0,00000 0,00000 69,06880 0,00000 0,00000 0,00000 0,00000 31,61588 0,00000 0,00000 0,00000 0,00000 8,82157 

WHAT IS NEEDED:

14.9506245839579,0,0,0,0,6.90687968992126,0,0,0,0,3.16158756810842,0,0,0,0,0.88215732592823

What do I change in the for loop?

I would imagine "culture"; try using ToString("F5", CultureInfo.InvariantCulture)

Also - look at StringBuilder for building a string in a loop.

What is the result if you just use

CSstr += S[i, j] + " ,  \t";

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM