繁体   English   中英

如何在SQL Server中创建存储过程并通过C#代码使用该过程的一些参数从该过程中调用该过程

[英]How to create stored procedure in sql server and call that procedure from C# code behind with some parameters to that procedure

我正在尝试在sql服务器上创建以下存储过程Lat和Lng是从后面的C#代码传递的参数。但是我无法创建此存储过程,它指示错误,并指出未定义的列名Lat,Lng

CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
    RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS(  (Lat/@b)  ) * COS( ( Lng/@b ) - (@c/@b) )  + SIN( @a/@b ) * SIN(  Lat/@b  ) ) )    
END

这是我从C#代码后面查询的内容。

sqlda.SelectCommand.CommandText = "select *, spherical_distance( Lat, 57.2958, Lng) as distance
                                     from business 
                                    where (( distance < '" + radius + "' )
                                      and (StreetName like '%" + streetname + "%')
                                      and (Keyword like '%" + keyword1 + "%' )) 
                                 order by spherical_distance(Lat,57.2958,Lng)";

这是view子句

create view [dbo].[business] as 
SELECT Id,
       Name1,
       ZipCode,
       StreetName,
       StreetNumber,
       State1,
       Lat,
       Lng,
       Keyword
  FROM Business_Details

您将参数命名为@a和@c,而不是LON和LAT。

CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
    RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS(  (Lat/@b)  ) * COS( ( @c/@b ) - (@c/@b) )  + SIN( @a/@b ) * SIN(  @a/@b  ) ) )    
END

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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