Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 15, 2011 08:25 PM by Careed
Sep 15, 2011 05:15 PM|LINK
I have a classic vb code which i need to convert to C#. Could somebody help me?
" where 1.15077*60*degrees(acos((sin(radians(" & orgLat & "))*sin(radians(latnorth)))+(cos(radians(" & orgLat & "))*cos(radians(latnorth))*cos(radians(" & orgLong & ")-radians(longwest))))) < " & pstrOrgMiles & ")"
My Starting approach for ==> degrees(acos((sin(radians(" + orgLatitude + ")) ==> is as follows:-
double firstPart = 0.0;
firstPart = Math.Acos(Math.Sin(Convert.ToDouble(orgLatitude))) * (180 / Math.PI);
Sep 15, 2011 05:30 PM|LINK
Your strSQL string does not contain Visual Basic code; it contains T-SQL code as this is the WHERE clause for an SQL query. Thus, since this is for SQL Server and not your actual program, no conversion is necessary.
Sep 15, 2011 06:06 PM|LINK
I removed the strSql. This variable been used in program as a string variable in classic visual basic code and used for concatination. Please ignore that help me with the rest of the Math function code conversion.
Sep 15, 2011 06:16 PM|LINK
My point is that the functions you list are T-SQL functions, not Visual Basic.
So, are you still using a WHERE clause? If not, then are you trying to do this functionality in C# directly? If this is the case, then we could try to proceed with your "conversions".
Sep 15, 2011 07:04 PM|LINK
Yes i am appending them in C# and passing them as sql string (Ex:- sqlStr) along with where clause to database. Since lot of dynamic sql is there, so i am using
So according i can pass them as it is as these are T-SQL functions. I need not convert them using System.Math library of C#. Am i correct or am i missing something here?
connection = new
command.Connection = connection;
command.CommandTimeout = 120;
command.CommandText = sqlStr;
Actual string is as follows:-
strSQL = strSQL & " where 1.15077*60*degrees(acos((sin(radians(" & orgLat & "))*sin(radians(latnorth)))+(cos(radians(" & orgLat & "))*cos(radians(latnorth))*cos(radians(" & orgLong & ")-radians(longwest))))) < " & pstrOrgMiles
Sep 15, 2011 08:25 PM|LINK
Your are correct. If you are passing the actual SQL statement, then you do not need to use any C#/.NET methods in your statement. Everything should work with T-SQL.
Note, of course, that the ampersands (&) need to replaced with plus (+) signs.