gpt4 book ai didi

C# mysql参数,点列错误

转载 作者:行者123 更新时间:2023-11-29 05:41:42 25 4
gpt4 key购买 nike

使用代码时,我不断收到错误“无法从发送到 GEOMETRY 字段的数据中获取几何对象”但是,如果我将字符串复制并粘贴到 MySQL 编辑器中,查询运行正常。有什么想法吗?

string geoPOINTSTRING = splitZippy[4] + " " + splitZippy[5];
string atGvar = "GeomFromText('Point(" + geoPOINTSTRING + ")');";
string mySQLfinishedProcessing = " insert into zipcodes " +
"set zipcode = '" + zipcodeString + "'" +
",State = '" + StateString + "'" +
",City = '" + CityString + "'" +
",GEOPoint = @g"+
",StateCode = '" + StateCodeString2 + "'";
MySqlConnection configCON = new MySqlConnection(SQLStringClass.zipCONString);
MySqlCommand CounterLogs = new MySqlCommand(mySQLfinishedProcessing, configCON);
CounterLogs.Parameters.AddWithValue("@g",(string)atGvar);
configCON.Open();
CounterLogs.ExecuteNonQuery();
configCON.Close();

最佳答案

您完全是在滥用参数。

参数是原始值。
您正在将 GEOPoint 设置为文字 string GeomFromText('Point(something)');

您需要将实际值放入参数中——zipcodeStringStateStringCityStringgeoPOINTSTRINGStateCodeString2.

然后您将编写 GEOPoint = GeomFromText(@pointString),其中 pointString 是包含 "Point("+ geoPOINTSTRING + ")"(你要传递给 GeomFromText 的字符串)

关于C# mysql参数,点列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6346899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com