开发者

C# mysql parameters, point column error

开发者 https://www.devze.com 2023-03-13 09:54 出处:网络
Using the code I keep getting the error \"Cannot get geometry object from data you send to the GEOMETRY field\"However, if i copy and paste the string into an MySQL editor the query runs fine.Any thou

Using the code I keep getting the error "Cannot get geometry object from data you send to the GEOMETRY field" However, if i copy and paste the string into an MySQL editor the query runs fine. Any thoughts?

str开发者_开发百科ing 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();


You are completely misusing parameters.

A parameter is a raw value.
You're setting GEOPoint to the literal string GeomFromText('Point(something)');

You need to put the actual values in parameters—zipcodeString, StateString, CityString, geoPOINTSTRING, and StateCodeString2.

You would then write GEOPoint = GeomFromText(@pointString), where pointString is a parameter holding "Point(" + geoPOINTSTRING + ")" (The string you want to pass to GeomFromText)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号