So I'm trying to pass in parameters for point strings, all my columns are marked not null in my DB however when i try to run the below code it tells me column Lat cannot be null. Is there something i'm overlooking?
string latParameter = "'Point(" + latString + ")'";
string lonParameter = "'Point(" + lonString + ")'";
string mySQLfinishedProcessing = " insert into zipcodes " +
"set zipcode = '" + zipcodeString + "'" +
",State = '" + StateString + "'" +
",City = '" + CityString + "'" +
",lat = GeomFromText(@latParam)"+
",lon = GeomFromText(@lonParam)"+
",StateCode = '" + StateCodeString2 + "'";
//File.AppendAllText(@"C:\sqlupdater.txt", mySQLfinishedProcessing + ";\n");
MySqlConnection configCON = new MySqlConnection(SQLStringClass.zipCONString);
MySqlCommand CounterLogs = new MySqlCommand(mySQLfinishedProcessing, configCON);
CounterLogs.Parameters.Add(new MySqlParameter("@latParam", latParameter));
CounterLogs.Parameters.Add(new MySqlParameter("@lonParam", lonParameter));
configCON.Open();
CounterLogs.开发者_C百科ExecuteNonQuery();
configCON.Close();
yes, latString and lonString has values.
string latParameter = 'Point(40.92233)' string lonParameter = 'Point(-72.63708)'
okay it appears the be cause there is only a single reference to a point, i change string latParameter = 'Point(40.92233 12)' it takes just fine. But do I really want to put both my lat/lon in 1 point column?
ugh nevermind that works fine in MySQl Edit, but in C# it still doesnt resolve the issue. The problem is the string lonParameter needs to contain a ;
here is the correct code.
string latParameter = "Point(" + latString + " " +lonString+");";
string mySQLfinishedProcessing = " insert into zipcodes " +
"set zipcode = '" + zipcodeString + "'" +
",State = '" + StateString + "'" +
",City = '" + CityString + "'" +
",Location = GeomFromText(@latParam)"+
",StateCode = '" + StateCodeString2 + "'";
//File.AppendAllText(@"C:\sqlupdater.txt", mySQLfinishedProcessing + ";\n");
MySqlConnection configCON = new MySqlConnection(SQLStringClass.zipCONString);
MySqlCommand CounterLogs = new MySqlCommand(mySQLfinishedProcessing, configCON);
CounterLogs.Parameters.Add(new MySqlParameter("@latParam", latParameter));
configCON.Open();
CounterLogs.ExecuteNonQuery();
configCON.Close();
you are writing insert statment with wrong syntax. it must be
string mySQLfinishedProcessing = " insert into zipcodes(zipcode ,State ,City ,lat ,lon ,StateCode ) values ( " +
"'" + zipcodeString + "'" +
",'" + StateString + "'" +
",'" + CityString + "'" +
",GeomFromText(@latParam)" +
",GeomFromText(@lonParam)" +
",'" + StateCodeString2 + "')";
If GeomFromText is a db function, it's probably returning null for whatever you're passing in.
精彩评论