void CTempretureImpl::InsertDataToMySql(vector<CTempData*> tempvec)
{
	CDatabase *db = CDbConnect::GetInstance()->getDatabase();
	if (!db->BeginTrans())
		return;
	for (int i = 0; i < tempvec.size(); i++){
		CString sql;
		sql.Format(_T("insert into tempreture(tempreture,time) values('%s','%s')"), tempvec.at(i)->GetTemperature(), tempvec.at(i)->GetTime());
		db->ExecuteSQL(sql);
	}
	db->CommitTrans();

}
Beispiel #2
0
//定义的删除数据的函数
_declspec(dllexport) int WINAPI deldata(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(res==NULL)
		return 1;
	whichtab=1;
	CString str,conn;
	crt_conn(conn);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,conn);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll-008",0);
		return 1;
	}
	str.Format("%s",(char*)res);
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,str);}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-010",0);
		return 1;
	}
	if(mrd.IsEOF() || !mrd.CanUpdate() || !mrd.CanTransact())
	{
		MessageBox(NULL,"delete result error!","from dll-009",0);
		mrd.Close();
		db.Close();
		return 1;
	}
/*	mrd.MoveFirst();
	while(!mrd.IsEOF())
	{
		mrd.Delete();
		mrd.MoveNext();
	}
*/
	mrd.Delete();
	db.CommitTrans();
	mrd.Close();
	db.Close();
	return 0;
};
void CTempretureImpl::InsertDataToMySql(CTempData* temp)
{
	CDatabase *db = CDbConnect::GetInstance()->getDatabase();
	if (!db->BeginTrans())
		return;
	int n = 3;
	while (n--)
	{
		CString sql;
		sql.Format(_T("insert into tempreture(tempreture,time) values('%s','%s')"), temp->GetTemperature(), temp->GetTime());
		db->ExecuteSQL(sql);
	}
	db->CommitTrans();

}