insert into 語句總是出現 未指定錯誤,insertinto

來源:互聯網
上載者:User

insert into 語句總是出現 未指定錯誤,insertinto
作者:BY  www.gudianxiaoshuo.com


本文由 代碼助手軟體 整理髮布 內容與本軟體無關更愜意的讀、更舒心的寫、更輕鬆的發布

 秀色書文軟體  可聽、可讀、可寫、可知識挖掘、可標註,再加上史上最強大的純文字配色功能, 瞬間使您的書文秀色起來。










insert into 語句總是出現 未指定錯誤

      CString strCmd;     strCmd.Format(_T("insert into Keshi values(%d,\"%s\")"),         nKeshi,         keshiName         );

原因,用ACCESS 產生的資料庫, 製作表時 有一個預設的欄位 儲存自動ID的,將其刪除掉即可

        //沒有此學生的話 則插入學生記錄        strCmd.Format(            _T("insert into 班級表%d(學號,姓名,地址,連絡方式,備忘)  values(%d,\"%s\",\"%s\",\"%s\",\"%s\")"),            m_pParentStudentInfo->m_nClassID,            nXuehao,            nameStr,            addStr,            lianxiStr,            beizhuStr);        spCmd->CommandText=(LPCTSTR)strCmd;        spCmd->Execute(NULL,NULL,adCmdText);    _CommandPtr spCmd;        spCmd.CreateInstance(__uuidof(Command));        spCmd->ActiveConnection=m_pConnection; 

        //確定是否已有此學生        CString strCmd;        strCmd.Format(            _T("select count(*) from 班級表%d where 學號=%d"),            m_pParentStudentInfo->m_nClassID,            nXuehao);        _RecordsetPtr pRecordSet;        long count=0;        spCmd->CommandText=(LPCTSTR)strCmd;        pRecordSet=spCmd->Execute(NULL,NULL,adCmdText);        count=(long)pRecordSet->GetCollect ((long)0);        if (count>0)        {            AfxMessageBox (L"已經存在此學號,請輸入下一個學生的學號");            return FALSE;        }

        //開啟此學生的記錄集        // +----------------------------------------------        pRecordSet.CreateInstance(__uuidof(Recordset));        strCmd.Format(            _T("SELECT * FROM 班級表%d order by 學號 "),            m_pParentStudentInfo->m_nClassID);        pRecordSet->Open((_variant_t)strCmd,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);            pRecordSet->AddNew();        pRecordSet->PutCollect(_T("學號"),(long)nXuehao);        pRecordSet->PutCollect(_T("姓名"),(LPCTSTR)nameStr);        pRecordSet->PutCollect(_T("性別"),(LPCTSTR)sexStr);        pRecordSet->PutCollect(_T("地址"),(LPCTSTR)addStr);        pRecordSet->PutCollect(_T("連絡方式"),(LPCTSTR)lianxiStr);        pRecordSet->PutCollect(_T("備忘"),(LPCTSTR)beizhuStr);        pRecordSet->Update();

批量插入記錄 到所有受影響的表中

//為指定學期的課堂成績表 增加學生BOOL CStuLianxi::AddXueqiStudent(const int nXueqi,const int nXuehao,const CString &nameStr){    _CommandPtr spCmd;      spCmd.CreateInstance(__uuidof(Command));      spCmd->ActiveConnection=m_pConnection;      CString strCmd;    _RecordsetPtr  pRecordSet;    long count=0;    try{        strCmd.Format(            _T("select count(*) from 課堂成績表%d where 學號=%d"),            nXueqi,            nXuehao);        spCmd->CommandText=(LPCTSTR)strCmd;        pRecordSet=spCmd->Execute(NULL,NULL,adCmdText);        count=(long)pRecordSet->GetCollect ((long)0);        if (count>0)        {  //以存在此學號            return TRUE;            }        //將此學生插入課堂成績表中        strCmd.Format(            _T("insert into 課堂成績表%d(學號,姓名,優秀,良,一般,曠課,主動加分)  values(%d,\"%s\",0,0,0,0,0)"),            nXueqi,            nXuehao,            nameStr);        spCmd->CommandText=(LPCTSTR)strCmd;        spCmd->Execute(NULL,NULL,adCmdText);    }    catch(_com_error &e)    {        AfxMessageBox(e.Error ());        return FALSE;    }    return TRUE;}

//為所有受影響的學生表中 新增學生BOOL CStuLianxi::AddAllaffectedXueqiStudent(const int nXuehao,const CString &nameStr){    try{        CString strCmd;        _RecordsetPtr  pRecordSet;        pRecordSet.CreateInstance(__uuidof(Recordset));        int nXueqiID=0;        //更新本班所有相關的課堂成績表        //尋找本班所有學期        strCmd.Format(            _T("SELECT * FROM ClassInfo where 班級ID=%d"),            m_pParentStudentInfo->m_nClassID);        pRecordSet->Open ((LPCTSTR)strCmd,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);        if (!pRecordSet->adoBOF)        {            pRecordSet->MoveFirst ();        }else            return FALSE;        //更新本班所有學期        _variant_t varValue;        while (!pRecordSet->adoEOF)        {            varValue=pRecordSet->GetCollect (_T("ID"));            if (varValue.vt!=VT_NULL)            {                nXueqiID=_ttoi((LPCTSTR)_bstr_t(varValue));                AddXueqiStudent(nXueqiID,nXuehao,nameStr);            }else{                pRecordSet->MoveNext ();                continue;            }            pRecordSet->MoveNext ();        }    }    catch(_com_error &e)    {        AfxMessageBox(e.ErrorMessage());    }    return TRUE;}


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.