我增加了一条语句,为什么添加不进去sqlserver表里面了~
之前是if (posList[i].Lo != 0)
{
posList[i].Oil = posList[i].Oil * car.Oil / 100;
sb.Length = 0;
sb.Append(car.CarID).Append(",");
sb.Append(posList[i].Pointed ? 1 : 0).Append(",");
sb.Append(posList[i].Lo).Append(",");
sb.Append(posList[i].La).Append(",");
sb.Append(posList[i].Speed).Append(",");
sb.Append(posList[i].Angle).Append(",");
sb.Append(posList[i].Mileage).Append(",");
sb.Append(posList[i].Oil).Append(",");
sb.Append(posList[i].Temperature).Append(",");
sb.Append(posList[i].Humidity).Append(",");
sb.Append(posList[i].Smoke).Append(",");
sb.Append(posList[i].Voltage).Append(",");
sb.Append(posList[i].Status).Append(",");
sb.Append(posList[i].Alarm).Append(",");
sb.Append(posList[i].StatusEx).Append(",");
sb.Append(posList[i].AlarmEx).Append(",)");
backDBThread.AddOperation("INSERT INTO " + Constant.T_POSITION + "(carID,pointed,lo,la,speed,direction,mileage,oil,temperature,humidity,smoke,voltage,status,alarm,statusEx,alarmEx,geoInfo) VALUES (" + sb.ToString());
}
可以插入表格position,只不过DateTime字段gpsTime为NULL,
我添加了一条语句sb.Append(Convert.ToDateTime(posList[i].GpsTime)).Append(","); 那个posList[i].GpsTime为string类型,添加了这条语句后,tposition添加不了数据了,哪里出错了?
if (posList[i].Lo != 0)
{
posList[i].Oil = posList[i].Oil * car.Oil / 100;
sb.Length = 0;
sb.Append(car.CarID).Append(",");
sb.Append(Convert.ToDateTime(posList[i].GpsTime)).Append(",");
sb.Append(posList[i].Pointed ? 1 : 0).Append(",");
sb.Append(posList[i].Lo).Append(",");
sb.Append(posList[i].La).Append(",");
sb.Append(posList[i].Speed).Append(",");
sb.Append(posList[i].Angle).Append(",");
sb.Append(posList[i].Mileage).Append(",");
sb.Append(posList[i].Oil).Append(",");
sb.Append(posList[i].Temperature).Append(",");
sb.Append(posList[i].Humidity).Append(",");
sb.Append(posList[i].Smoke).Append(",");
sb.Append(posList[i].Voltage).Append(",");
sb.Append(posList[i].Status).Append(",");
sb.Append(posList[i].Alarm).Append(",");
sb.Append(posList[i].StatusEx).Append(",");
sb.Append(posList[i].AlarmEx).Append(",)");
backDBThread.AddOperation("INSERT INTO " + Constant.T_POSITION + "(carID,gpsTime,pointed,lo,la,speed,direction,mileage,oil,temperature,humidity,smoke,voltage,status,alarm,statusEx,alarmEx,geoInfo) VALUES (" + sb.ToString());
} --------------------编程问答-------------------- 除 --------------------编程问答-------------------- if(DateTime.TryParse(str, out dt))
return dt;
有些类型转换的问题你得注意一下,至于为什么没有添加进去 你debugger一下,监视看看哪儿错了,不就可以了 --------------------编程问答-------------------- sb.Append("'"+Convert.ToDateTime(DateTime.Now)+"'").Append(",");
--------------------编程问答-------------------- thanks!
补充:.NET技术 , C#