所以我试图传入点字符串的参数,我的所有列都在我的数据库中标记为非null但是当我尝试运行下面的代码时它告诉我列Lat不能为空。我有什么东西可以忽略吗?
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.ExecuteNonQuery();
configCON.Close();
是的,latString和lonString有值。
string latParameter ='Point(40.92233)' string lonParameter ='Point(-72.63708)'
好吧它似乎是因为只有一个点的一个引用,我改变字符串latParameter ='点(40.92233 12)'它就好了。但我真的想把我的纬度/经度放在1点列中吗?
在MySQl Edit中没有任何关系可以正常工作,但在C#中它仍然无法解决问题。问题是字符串lonParameter需要包含一个;
这是正确的代码。
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();
答案 0 :(得分:1)
您正在使用错误的语法编写插入语句。它一定是
string mySQLfinishedProcessing = " insert into zipcodes(zipcode ,State ,City ,lat ,lon ,StateCode ) values ( " +
"'" + zipcodeString + "'" +
",'" + StateString + "'" +
",'" + CityString + "'" +
",GeomFromText(@latParam)" +
",GeomFromText(@lonParam)" +
",'" + StateCodeString2 + "')";
答案 1 :(得分:0)
如果GeomFromText是一个db函数,它可能会为你传入的任何内容返回null。