一
數(shù)據(jù)庫操作
m_pConn->Execute((_bstr_t)strSQL , &index , 1);
第二個參數(shù)的值是影響的行數(shù)
有了這個 就可以在Update數(shù)據(jù)庫的記錄的時候不用先Select查看是否存在數(shù)據(jù)而執(zhí)行兩條SQL語句影響服務器的效率了
二
捕獲ADO的數(shù)據(jù)庫操作的異常
catch(_com_error e)
{
::AfxMessageBox(e.Description() , MB_OK);
return FALSE;
}
三
將double類型的時間轉換成時間字符串
CString strGPSTime;
COleDateTime GPStime(GPSDate.gpsTime);
strGPSTime = GPStime.Format("%Y-%m-%d %H:%M:%S"); //GPS時間
四
小技巧 在MFC的編輯框顯示信息的時候 我以前一般都是 直接
m_strMsg += "提示信息:";
這樣會出現(xiàn)往下拖 很煩人
今天剛想到一個小技巧
在插入信息的時候 我們可以插入到頭部去 這樣就不會滾動 我們看到的就是最新的信息了
m_strMsg.Insert(0 , "信息提示:");
//10.22 新增
對話框的巧妙隱藏 不閃屏!
隱藏窗口
void CFlashThiefDlg::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpwndpos);
}
五
判斷數(shù)據(jù)庫中的一張表是否存在的函數(shù)
//判斷一張表是否存在
BOOL IsTableExsist(CString strTableName)
{
try
{
CStringArray arrTableNames;
_RecordsetPtr Recordset = m_pConn->OpenSchema(adSchemaTables);
_variant_t l_vDBTableName;
_bstr_t bstrTableType;
while(!Recordset->adoEOF)
{
l_vDBTableName = Recordset->GetCollect("TABLE_NAME");
bstrTableType = Recordset->GetCollect("TABLE_TYPE");
if ((bstrTableType == (_bstr_t)"TABLE")||(bstrTableType == (_bstr_t)"VIEWS"))
{
arrTableNames.Add((char *)_bstr_t(l_vDBTableName));
}
Recordset->MoveNext();
}
int iCount = arrTableNames.GetSize();
for (int i = 0 ; i < iCount ; i++)
{
CString& strName = arrTableNames[i];
if (strName == strTableName)
return TRUE;
}
}
catch(_com_error& e)
{
ASSERT(FALSE);
CString str;
str.Format("文件名稱: %s \n 所在代碼行 : %d 執(zhí)行SQL語句失敗 錯誤原因 %s" , __FILE__ , __LINE__ , (LPCSTR)e.Description());
TRACE(str);
AfxMessageBox(str);
return FALSE;
}
return FALSE;
}
以后再繼續(xù)
posted on 2009-09-11 16:06
李佳 閱讀(711)
評論(0) 編輯 收藏 引用 所屬分類:
奇技淫巧