C# SQL Geometry Error: Invalid operator for data type. Operator equals equal to, type equals geometry

C# SQL Geometry Error: Invalid operator for data type. Operator equals equal to, type equals geometry

使用 C# 和本地 SQL 服务器 进行 SQL 调用,即:

string cmd2 = "SELECT Circle_ID FROM Circle WHERE Center_Point = geometry::STGeomFromText('POINT(";
        cmd2 += center_lat;
        cmd2 += " ";
        cmd2 += center_lng;
        cmd2 += ")',0)";

我收到错误:

Invalid operator for data type. Operator equals equal to, type equals geometry. Error Number:403,State:1,Class:16

我认为引用 #Ref1 and #Ref2.

的语法是正确的

注意:我了解我将执行的参数化 sql 查询。但首先我只想让 sql 正常工作。 谢谢

该数据类型允许进行某些操作,并不符合标准。

我找到的解决方案是:

 string cmd2 = "SELECT Circle_ID FROM Circle WHERE Center_Point.STEquals(geometry::STGeomFromText('POINT(";
        cmd2 += center_lat;
        cmd2 += " ";
        cmd2 += center_lng;
        cmd2 += ")',0)) = 1;"; // 1 = TRUE

This post 帮了我大忙。

希望这对以后的其他人有所帮助。