C#mysql参数,点列错误
本文关键字:错误 参数 C#mysql | 更新日期: 2023-09-27 17:59:12
使用代码,我不断收到错误"无法从发送到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
设置为文字字符串GeomFromText('Point(something)');
您需要将实际值放入参数中—zipcodeString
、StateString
、CityString
、geoPOINTSTRING
和StateCodeString2
。
然后编写GEOPoint = GeomFromText(@pointString)
,其中pointString
是一个包含"Point(" + geoPOINTSTRING + ")"
(要传递给GeomFromText
的字符串)的参数