The insert into statement always has an unspecified error, insertinto

Source: Internet
Author: User

The insert into statement always has an unspecified error, insertinto
Author:Www.gudianxiaoshuo.com


This article is organized by the Code Assistant Software and released content is irrelevant to this software.More comfortable reading, more comfortable writing, and easier Publishing

The show-colored book and Text software is audible, readable, writeable, knowledgeable, and annotated. Coupled with the most powerful pure text color function in history, you can instantly show your book and text.










The insert into statement always has an unspecified error.

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

Cause: the database generated by using ACCESS has a default field for saving the automatic ID when creating the table. Delete it.

// If this student does not exist, insert the student record strCmd. format (_ T ("insert into class Table % d (student ID, name, address, contact information, remarks) values (% d, \" % s \", \ "% s \", \ "% s \", \ "% s \") "), m_pParentStudentInfo-> m_nClassID, nXuehao, nameStr, addStr, lianxiStr, beizhuStr ); spCmd-> CommandText = (LPCTSTR) strCmd; spCmd-> Execute (NULL, NULL, ad1_text); _ CommandPtr spCmd; spCmd. createInstance (_ uuidof (Command); spCmd-> ActiveConnection = m_pConnection;

// Determine whether the student CString strCmd; strCmd exists. format (_ T ("select count (*) from class Table % d where student ID = % d"), m_pParentStudentInfo-> m_nClassID, nXuehao); _ RecordsetPtr pRecordSet; long count = 0; spCmd-> CommandText = (LPCTSTR) strCmd; pRecordSet = spCmd-> Execute (NULL, NULL, ad1_text); count = (long) pRecordSet-> GetCollect (long) 0); if (count> 0) {AfxMessageBox (L "this student ID already exists; enter the student ID"); return FALSE ;}

// Open this student's record set // + ------------------------------------------------ pRecordSet. createInstance (_ uuidof (Recordset); strCmd. format (_ T ("SELECT * FROM class Table % d order by student ID"), m_pParentStudentInfo-> m_nClassID); pRecordSet-> Open (_ variant_t) strCmd, m_pConnection.GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adshorttext); pRecordSet-> AddNew (); pRecordSet-> PutCollect (_ T ("student ID"), (long) nXuehao ); pRecordSet-> PutCollect (_ T ("name"), (maid) nameStr); pRecordSet-> PutCollect (_ T ("gender"), (maid) sexStr ); pRecordSet-> PutCollect (_ T ("Address"), (LPCTSTR) addStr); pRecordSet-> PutCollect (_ T ("Contact Info"), (LPCTSTR) lianxiStr ); pRecordSet-> PutCollect (_ T ("Remarks"), (LPCTSTR) beizhuStr); pRecordSet-> Update ();

Batch insert records to all affected tables

// Add the student 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 classroom sequence table % d where student ID = % d"), nXueqi, nXuehao); spCmd-> CommandText = (LPCTSTR) strCmd; pRecordSet = spCmd-> Execute (NULL, NULL, ad1_text); count = (long) pRecordSet-> GetCollect (long) 0); if (count> 0) {// return TRUE;} // Insert the student into the classroom student table strCmd. format (_ T ("insert into classroom sequence table % d (student ID, name, excellent, good, general, absent, take the initiative to add points) values (% d, \" % s \", 0, 0, 0, 0) "), nXueqi, nXuehao, nameStr); spCmd-> CommandText = (LPCTSTR) strCmd; spCmd-> Execute (NULL, NULL, ad1_text );} catch (_ com_error & e) {AfxMessageBox (e. error (); return FALSE;} return TRUE ;}

// Add the student BOOL CStuLianxi: pair (const int nXuehao, const CString & nameStr) {try {CString strCmd; _ RecordsetPtr pRecordSet; pRecordSet. createInstance (_ uuidof (Recordset); int nXueqiID = 0; // update the sequence table of all related classes in this class. // find strCmd for all semesters in this class. format (_ T ("SELECT * FROM ClassInfo where class ID = % d"), m_pParentStudentInfo-> m_nClassID); pRecordSet-> Open (LPCTSTR) strCmd, m_pConnection.GetInterfacePt R (), adOpenDynamic, adLockOptimistic, adshorttext); if (! PRecordSet-> adoBOF) {pRecordSet-> MoveFirst ();} else return FALSE; // update all semesters _ variant_t varValue; while (! PRecordSet-> adoEOF) {varValue = pRecordSet-> GetCollect (_ T ("ID"); if (varValue. vt! = VT_NULL) {nXueqiID = _ ttoi (LPCTSTR) _ bstr_t (varValue); Round (nXueqiID, nXuehao, nameStr);} else {pRecordSet-> MoveNext (); continue;} pRecordSet-> MoveNext () ;}} catch (_ com_error & e) {AfxMessageBox (e. errorMessage ();} return TRUE ;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.