Mysql

xiaoxiao2021-03-06  15

Mysql> Create Database School; Mysql> Use School; Database Changedmysql> Create Table Teacher -> (-> ID INT (3) Auto_Increment Not Null Primary Key, -> Name Char (10) Not null, ->); mysql> Insert INTO TEACHER VALUES (',' Glcheng '); MySQL> Insert Into Teacher Values ​​(' ',' Jack '); MySQL> Use School; MySQL> Select * from Teacher; ---- ----- ------- | ID | NAME |

-- ------------ | 1 | Glchengang |

| 2 | Jack |

---- ------------

*********************************************************** *********************************************************** *************

// kkkk.cpp: defines the entry point for the console application.//

#include "stdafx.h" #include "kkkk.h"

#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF

/// the one and only application objection Object

CWINAPPPP;

Using namespace std;

#import "c: / program files / compo files / system / ado / msado15.dll" / no_namespace rename ("eof", "endoffile")

#include #include #include // for cstring ()

Using Namespace Std; Class Stu {public: char ID [10]; char name [10]; public: stu () {} ~ stu ()}};

INT _TMAIN (int Argc, tchar * argv [], tchar * envp []) {int nretcode = 0;

// Initialize MFC and Print and Error On Failure if (! AFXWininit (: getModuleHandle (Null), Null, :: getcommandline (), 0)) {// Todo: Change Error Code To Suit Your Needs CERR << _t "Fatal Error: MFC Initialization Failed") << Endl; Nretcode = 1;} else {// Todo: Code Your Application's Behavior Here.

Stu Student; CString Strname, Strid ;:: Coinitialize (NULL); // Initialize the OLE / COM library environment, prepare for accessing ADO interface

_RecordSetPtr M_PRecordset ("AdoDb.Recordset"); _ConnectionPtr M_PConnection ("AdoDb.Connection");

_BSTR_T BSTRSQL ("Select * from Teacher"); // Query statement char * query_cmd = "delete from demotable where name = 'jack'";

Try {// Create a Connection object m_pconnection.createInstance ("AdoDb.Connection"); // Set the connection string, must be a BSTR or _BSTR_T type

_BSTR_T strconnect = "driver = {mysql odbc 3.51 driver}; server = localhost;" "Database = SCHOOL; user = root; password = 111111121; option = 4;";

M_PConnection-> Open (strconnect, ",", admodeunknown); if (m_pconnection == null) CERR << "Lind Data Error! / N"; // Create record set object m_precordset.createInstance (__ uuidof (recordset)) ; // Take the record m_precordset-> Open in the table (BSTRSQL, M_PConnection.GetInterfacePtr (), AdoPendynamic, AdlockOptimistic, AdcmdText);

_VARIANT_T VSID, VSNAME; // Id in the corresponding library, Name Cout << "ID name"; cout << "/ n ---------------------- ---------------------------- / n ";

While (! m_precordset-> endoffile) {vsid = m_precordset-> getCollect ("id"); vsname = m_precordset-> getCollect ("name");

IF (vsid.vt! = vt_null && vsname.vt! = vt_null) {strid = (lpcstr) _BSTR_T (vsID); strname = (lpcstr) _BSTR_T (VSNAME); Printf ("% s / t", strike; printf ("% s", strname); Printf ("/ n"); // A record is given back to a return} m_precordset-> moletnext (); /// Move to the next record} cout << "/ n- -------------------------------------------------- ------------- / N "; cout <<" / n Please enter the record / n "you want to add; cout <<" / id: "; cin >> student.id; Cout << "/ n name:"; cin >> student.name; m_precordset-> movefirst (); // Move to the first record m_precordset-> addnew (); // / Add new record atol (student.id ); M_precordset-> Putcollect ("ID", _ variant_t (student.id)); m_precordset-> Putcollect ("name", _ variant_t (student.name)); m_precordset-> update ();

m_pconnection-> execute (query_cmd, null, 1); // execute the SQL statement with Execute to delete getchar (); m_precordset-> close (); // Close record set}

// Capture an abnormality catch (_COM_ERROR E) {// Display Error Message CERR <<< / Nerror: "<< (char *) E.DESCRIPTION (); // is thrown out to getChar ();} if (M_PConnection -> State) m_pconnection-> close ();

:: Couninitialize ();

}

Return nretcode;}

转载请注明原文地址:https://www.9cbs.com/read-47985.html

New Post(0)