/// <summary> /// 添加所有数据一行 /// </summary> /// <param name="RLDs">所添加数据</param> /// <returns></returns> public int AddAllDatasOnce(MyLOG_DATAs RLDs) { int reanswer = 0; SqlCeParameter[] paras = new SqlCeParameter[] { new SqlCeParameter("@NUM", RLDs.NUM), new SqlCeParameter("@Time", RLDs.Time), new SqlCeParameter("@RunTime", RLDs.RunTime) , new SqlCeParameter("@JYW_ID", RLDs.logData.JYW_ID), new SqlCeParameter("@JD_ID", RLDs.logData.JD_ID), new SqlCeParameter("@Temp", RLDs.logData.Temperture.MyValue) , new SqlCeParameter("@Humidity", RLDs.logData.Humidity.MyValue), new SqlCeParameter("@PM0", RLDs.logData.PM.MyValue) }; SqlCeCommand cmd = myConn.CreateCommand(); cmd.CommandText = "INSERT INTO ROV_ALLDAT VALUES(@NUM,@Time,@RunTime,@JYW_ID,@JD_ID,@Temp,@Humidity,@PM0) "; cmd.Parameters.AddRange(paras); try { reanswer = cmd.ExecuteNonQuery(); } catch (SqlCeException cee) { MessageBox.Show(cee.Message); reanswer = -1; } return(reanswer); }
public MyLOG_DATA GetALLDatas() { MyLOG_DATA ALL_LOG = new MyLOG_DATA(); SqlCeCommand mySqlCommand = myConn.CreateCommand(); string sqlStatement = "select * from ROV_ALLDAT ";// "select * from TestTbl "; //设置CommandText属性 mySqlCommand.CommandText = sqlStatement; bool frist = true; SqlCeDataReader sqlreader = mySqlCommand.ExecuteReader(); nloadingData = 0; // 0 1 2 3 4 // "INSERT INTO ROV_ALLDAT VALUES(@Time,@RunTime,@CKT_SWITCHS,@CKT_ANALOG,@SENSERS) "; //"INSERT INTO ROV_ALLDAT VALUES(@NUM,@Time,@RunTime,@Heading,@Pitch,@Roll,@Lon,@Lat,@Altitude,@Acc_x,@Acc_y,@Acc_z,@Gry_x,@Gry_y,@Gry_z" // + ",@Vx,@Vy,@Vz,@Rev1,@Rev2,@Rev3,@Rev4) "; while (sqlreader.Read()) { MyLOG_DATAs alldat = new MyLOG_DATAs(); alldat.NUM = (int)sqlreader[0]; alldat.Time = (DateTime)sqlreader[1]; alldat.RunTime = double.Parse(sqlreader[2].ToString()); // alldat.logData.JYW_ID = int.Parse(sqlreader[3].ToString()); // alldat.logData.JD_ID = int.Parse(sqlreader[4].ToString()); //(float)sqlreader[4]; alldat.logData.Temperture.MyValue = float.Parse(sqlreader[5].ToString()); //(float)sqlreader[5]; alldat.logData.Humidity.MyValue = float.Parse(sqlreader[6].ToString()); //(double)sqlreader[6]; alldat.logData.PM.MyValue = float.Parse(sqlreader[7].ToString()); //(double)sqlreader[7]; //alldat.Altitude = float.Parse(sqlreader[8].ToString());// (double)sqlreader[8]; //alldat.Ax = double.Parse(sqlreader[9].ToString());//(double)sqlreader[9]; //alldat.Ay = double.Parse(sqlreader[10].ToString());// (double)sqlreader[10]; //alldat.Az = double.Parse(sqlreader[11].ToString());//(double)sqlreader[11]; //alldat.Gx = double.Parse(sqlreader[12].ToString());//(double)sqlreader[12]; //alldat.Gy = double.Parse(sqlreader[13].ToString());//(double)sqlreader[13]; //alldat.Gz = double.Parse(sqlreader[14].ToString());//(double)sqlreader[14]; //alldat.Vx = float.Parse(sqlreader[15].ToString());// (float)sqlreader[12]; //alldat.Vy = float.Parse(sqlreader[16].ToString());// (float)sqlreader[13]; //alldat.Vz = float.Parse(sqlreader[17].ToString());// (float)sqlreader[14]; //alldat.Rev1 = int.Parse(sqlreader[18].ToString()); //alldat.Rev2 = int.Parse(sqlreader[19].ToString()); //alldat.Rev3 = int.Parse(sqlreader[20].ToString()); //alldat.Rev4 = int.Parse(sqlreader[21].ToString()); if (frist) { frist = false; ALL_LOG.beginTime = (DateTime)sqlreader["Time"]; } ALL_LOG.ROV_LOG_DATA_List.Add(alldat); nloadingData++; } return(ALL_LOG); }