我查看了不同的链接(例如这个),但我仍然无法获得此错误消息的来源。我继续数列,昏迷等等,却找不到问题出在哪里。
int exId = stride.getExerciseId();
string timestamp = stride.getTimeStamp();
int startSec = stride.getBeginningSec();
int startMsec = stride.getBeginningMSec();
int endSec = stride.getEndSec();
int endMSec = stride.getEndMSec();
float length = stride.getLength();
float duration = stride.getDuration();
float steplength = stride.getStepLength();
float stepDuration = stride.getStepDuration();
string supportingFoot = stride.getSupportingFoot();
string query = "INSERT INTO singlesupportstate (ExerciseId , TimeStamp , SingleSupportStateStartSeconds , SingleSupportStateStartMSeconds , SingleSupportStateEndSeconds , SingleSupportStateEndMSeconds , StrideLength , StrideDuration , StepLength , StepDuration , SupportingFoot)
VALUES("+ exId +",'" + timestamp +"',"+ startSec +"," + startMsec + "," + endSec + "," + endMSec + "," + length +"," + duration + "," + steplength + "," + duration + ",'" + supportingFoot + "')";
if (this.OpenConnection() == true)
{
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
this.CloseConnection();
}
编辑 :
因此,我更改了代码以使用参数化查询,这是有效的新代码:
if (this.OpenConnection() == true)
{
MySqlCommand cmd = connection.CreateCommand() ;
cmd.CommandText = "INSERT INTO singlesupportstate (ExerciseId , TimeStamp , SingleSupportStateStartSeconds , SingleSupportStateStartMSeconds , SingleSupportStateEndSeconds , SingleSupportStateEndMSeconds , StrideLength , StrideDuration , StepLength , StepDuration , SupportingFoot) "
+" VALUES(@exId,@timestamp,@startSec,@startMsec,@endSec,@endMSec,@length,@duration,@steplength,@stepduration,@supportingFoot)";
cmd.Parameters.Add("@exId", MySqlDbType.Int32);
cmd.Parameters.Add("@timestamp",MySqlDbType.Timestamp);
cmd.Parameters.Add("@startMsec",MySqlDbType.Int32);
cmd.Parameters.Add("@startSec",MySqlDbType.Int32);
cmd.Parameters.Add("@endSec",MySqlDbType.Int32);
cmd.Parameters.Add("@endMSec",MySqlDbType.Int32);
cmd.Parameters.Add("@length", MySqlDbType.Float);
cmd.Parameters.Add("@duration",MySqlDbType.Float);
cmd.Parameters.Add("@steplength",MySqlDbType.Float);
cmd.Parameters.Add("@stepduration", MySqlDbType.Float);
cmd.Parameters.Add("@supportingfoot", MySqlDbType.Text);
cmd.Parameters["@exId"].Value = exId;
cmd.Parameters["@timestamp"].Value = timestamp;
cmd.Parameters["@startMsec"].Value = startMsec;
cmd.Parameters["@startSec"].Value = startSec;
cmd.Parameters["@endSec"].Value = endSec;
cmd.Parameters["@endMSec"].Value = endMSec;
cmd.Parameters["@length"].Value = length;
cmd.Parameters["@duration"].Value = duration;
cmd.Parameters["@steplength"].Value =steplength;
cmd.Parameters["@stepduration"].Value =stepDuration;
cmd.Parameters["@supportingfoot"].Value =supportingFoot;
cmd.CommandTimeout = 120;
cmd.ExecuteNonQuery();
this.CloseConnection();
}