DOC

Visual_2

By Esther Austin,2014-07-24 04:23
8 views 0
Visual_2Visual

    Visual

2008???Q24?cSCIENCE&TECHNOLOGYINFORMATION

    ;q?l2???-??????????

    ;ODBC(OpenDataBaseConnectivity,???-??????????)?u???????- ;?O??????q;?N??????????q?qb???Y???Cl0??????q?q??????8,????!? ;q?q??????m?T???8?m????l0?m???gq????????????????m?T??,?????? ;??????!?qO!???q?q?!??????????C????,qO????qLq?!?DBMS??q? ;??,?+???????????m?T????qO?HDBMS????q?l0????????!???it???? ;??is?????m?T???u?G?L??,?=?N??????????!??+????DBMS??ODBC ;?????T??(ODBCDriver)???Yl0?Nq?ODBC?????T??,???????+?????6 ;?C????,????q??u?Q?K?????????????/?G????q?(???Q?KDOS????qT ;??Access??q?*.mdb),q???q??u???T????????q?(??MicrosoftSQL ;Server);????q??u???]??????????DBMS?/?G,q???q??uq????????? ;???????/?Gl0?hq<,??????q???!?q?q?qX?????????????????T??l0 ;VisualC++q;??ODBCqh???u??????q?Windows?????????????????m ;????q?l0

    ;q?l2ODBC???C??

    ;?mODBCq;,???????uq?qb??????????,???u??????!]???????? ;????????????!??????h??l0???????m!??m?]?????n??ODBC???C?? ;(Administrator)???[????l0?m????????????,???o?S???????O ;(Datasourcename)l2????????q??O(Databasename)?????????/?O(Table ;name)??qN?S??????????q?????:?????????{?uq?????????????????, ;???????O?u???????<q???it????is???O??,q?!????m?T??!??m,??q??? ;??????qT???????u??q?qb??????,?e?+????????q??O?I??(??Access ;2.0forMSOfficsq;??.mdb??q?);q?qb????????q?q;??q??S??????qb ;???????/(table)????q?????l0?mODBC?k?v????????????q;,?????uq? ;q??????/?????G???mq?????????q?q;,???m?T??????????!????I???u ;??q????/q;???[(row????)???((columns????)????l0??q?foxpro???? ;??,????????q??O?uit?????Ois,?H??????qT???=?N??????q?(*.dbf)???? ;q???it????????q?is?OqT?????????/(table)l0ODBC???C???????m ;ControlPanel??(ODBCINST.CPL)l0?n??????????q?????l2!??1?B?i?? ;??????,q??m??????l2?i??ODBC?????T??,ODBC???C???????????? ;??q???????!???!????mODBC.INIl2ODBCINST.INI??ODBCISAM.INI ;q;l0????????q????m?T????,?????N??????????q?????????!]?????? ;????????l0

    ;qNl2ODBC???m?T??????

    ;ODBCAPI?uq????I????ODBC??????,??q?q??Q??????????!? ;?????B,???S??q???????(??SQLExec?BSQLExecdirect)???c???[?I?? ;SQL????????l0SQL(StructuredQueryLanguage?????B????????)?uq? ;?????????????????????I??????,???c??q?l2????l2!??1?????P????,

    ;?????????????c!??mq???qb???????/,???N???K??????l0 ;?HWindows3.1SDKq;API??!/,ODBCAPIq??u??q?????

    ;(handle)???[??!???l0API?????N???????CqKq?qT????: ;????????????????,????/?????N??!?????????;

    ;?????I/??q????[SQL??????????????????????????????; ;?????????????0?3?4?C????l0

    ;q&????????????q????Kq????[????????!???q??Q????l0q)qb???? ;???????f???L,q??u????????????:??????q;???????=???N???????? ;????qKSQL????????,??q??????????m????????q;????????????,qO ;q?????ODBCSQL???????????????Gq???,?????T??????q????????? ;?HODBCSQL???????????[??q?????,??q?qbODBCSQL?????????? ;????q?q?qbODBCC????????????;q??u???????8?m???f????,??qO ;?u??q?qbODB?????T?????u?2?=?N??ODBI?????8?m,?m???m ;?T??q;,??q??8?m?N???????????????T??q??u?2?k?v??????!???l0 ;??l2ODBC???m?B?T

    ;?mVisualC++q;,MFC(MicrosoftFoundationClass???Q????)?u?? ;????Windows???m?T??q;?4qb??q????[?????????H??????q??????? ;q?????,??????????(CWnd)l2?4???????-?c??????,??q????m???m?T?? ;q;??????!??m,qO??????????q?l0?mMFCq;,q?qKODBC????q?q??? ;qb??,??q;qh?????u????????(CDatabase)?????????E??(CRecoredset)l0 ;??q)qb?????N???????N?K?f,?m???m?T??q;,??q??C?f!??m,q???q??H ;??!??m,??q???q???q??H?????m?nqb????l0CDatabase????q?qb????q? ;??q?q?qb????????????,CRecordset????q?qb????q???q?q?q?qb???? ;??q;?N????????????q????????????????E,q??Q????,?]?S?0??q??? ;??????qT????qb???????/???[??!???!?,?L?S?mq????=?N?????????E ;???[?4?Cl0?HWindows??qLSDKAPI??????????q??g,CDatabase?? ;qLODBCAPI????q??N??!/??????,!}CDatabase??q;??qO?S?f?=?N ;??ODBCAPI????,?.???C??!?????q????????8?mODBCAPI????,?? ;????????????,?mq???????????qT?????????/!???,?????/?O,?????O ;??l0

    ;?m???m?B?T??,q??Q!??mCDatabase??CRecordset???-?c??l0?5?? ;?-?c???C?fqKCUserdb??CUserset,?H?m???m??CUserClassq;,!??mq? ;qbCUserdb????(m-db)??q?qbCuserset????(m-recset)

    ;1.m-db??????????

    ;m-db?m???Y??q????i?L,???8?mCDatabase??????(Open)????q? ;???[???????????{????:m-db.Open(lpszDSN,bExclusive,bReadOnly, ;lpszConnect);??????????????????qb????l0lpszDSN:???????????????? ;?O??,????lpszDSN=NULLqAlpszConnectq;q????N?I?L???????O,?e?? ;?8?m!n????????q?qb?????}?(???=?N???m????????(?O),???m?g?N??l0 ;bExclusive:???u?2it?5is(False)?/,???KqK??q?(share)???G????l0????,?? ;?m?T???m???[?],q?????????share.exe?B?mWindows??system.iniq; ;????vshare.386l0ReadOnly:?I?L????????!????G?uit????is???u??q? ;!??1l0lpszConnect:?I?L???????*qW,?S?????????Ol2?m?g?I???2l2??q? ;??!???l0?????*qW????q?itODBC;is???:,???K???????uqLq?qbODBC

    ;????????????(?8??q??L?X?Q?u?2??ODBC??????)l0m-db?????L,?? ;?I????q?!i??m-recset!?qK????????l0m-db?????L,?C?????=?N ;CRecordset??????????,m-dbq???q?????????l0

    ;2.m-db??!?????

    ;???????????L,??????????????q?q;?????????/???[??!?,??!?q? ;?8?mSQL???????G???[,???????n??ODBCAPI????,?B?SCDatabase ;???Y??????ExecuteSQLl0???????O?mSQL????q;?I??,??qT?????e?m ;?=?m????????q;??clerk??q;????q?qb????,??????name?????/qK”

    ;chen”l0m-db.ExecuteSQL(“insertintoclerk(name)value(„chen‟)”);

    ;3.m-recset????????m-recset?m???i??,??!i??q?qbCDatabase?? ;???I??,!?qKm-recset????????,??qKNULL??,????????CRecordset ;??????GetDefaultConnect,q???!??????????????*qW(????q?m-db. ;Openq;??lpszConnect)l0??qT?e???K?????OqKCOMPANY????????(?? ;!i??q??E????CDatabase?????I????,???????CqO???8?m)l0CString ;CUserset::GetDefaultConnect()

    ;{

    ;return”ODBC;DSN=COMPANY;”;

    ;}

    ;4.m-recset?N????????????

    ;?m?8?m??????????,??????q??*?E??q???q???????,??q? ;VisualC++q;??????????????

    ;?i????

    ;(???w?0?B????qn???v???????w110013)

    ;lY????lFODBC(OpenDataBaseConnectivity,???-??????????)??!?q?q??????m?T???

    8?m??????q??????[?u?2????,???m?T????q?!??m?I

    ;???????????[????????!?,?HqO????????????????q?!????????????C????(DBMS),???

    ??N???????????T??????l0?Q??q???q?ODBC?????[?K

    ;?P,?=??????q?VisualC++1.5qT???mMFC???[ODBC?B?T??????l0 ;lY???V??lFODBC;???C??;????;???m?B?T

    ;r?IT???u????r?

    ;6

    ;CCAP

    ;m-recset

    ;2

    ;2008???Q24?cSCIENCE&TECHNOLOGYINFORMATION

    ;??

    ;?????mOpen????q;??lpszSQLq;????,????lpszSQLqKNULL,?e?? ;??????CRecordset??????q???!???????l0???????uq?qbSELECT?? ;??,?*?BqO?*where??orderby????(????qO?*,where??Orderby?? ;??q?q????mCRecordset??q)qb????q??Y??????m-strFilter??m- ;strSortq;????)l0lpszSQLq???q????uq?qb???????O(table-name),q??? ;q??u?????[?m????????q?q;???????T?????8?m????l0?=?N????q????( ;?????O,?m?Y??????DoFieldExchangeq;?+q????(RFX-?????I??l0 ;RFX-(RecordFieldExchange)????,!????????Y??????q?q???????????

;??????l0???B,m-strFilterq;q???q??*????????(?m”?”???K,??”

    ;fieldl>=?ANDfield2<=?”),????qL?Y????????????????q??m

    ;DoFieldExchangeq;?+RFX-?????I??(qWq;??”?”?C???????????/?Yq?

    ;????)l0

    ;voidCUserset::DoFieldExchange(CFieldExchange*pFX) ;{

    ;pFX->SetFieldType(CFieldExchange::outputColumn); ;/*q?qTqK????????*/

    ;RFX-???(pFX,”field1”,m-var1);

    ;RFX-???(pFX,”field2”,m-var2);

    ;...

    ;RFX-???(pFX,”fieldn”,m-varn);

    ;pFX->SetFieldType(CFieldExchange::param); ;/*q?qTqK????????*/

    ;RFX-???(pFX,field1,m-param1);

    ;RFX-???(pFX,field2,m-param2);

    ;...

    ;}

    ;??q;,???qKODBCSQL?????????O,??RFX-Double,RFX-Text??l0 ;???Eq&??,?N???????????????{?u?+qT?(???????Y: ;SELECTrfx-field-listFROMtable-name[WHEREm-strFilter] ;[ORDERBYm-strSort]????????????????????qb??q??????m?8?m???? ;?????](?????i????q;)?????l?<?/???Y??????m-nFields??m- ;nParamsl0m-recset?m?????L??q?!????e?8?mRequery()????,?C?1???? ;????????q?(!???!??1q??????????/)?????N??????l0 ;5.m-recset??!?????

    ;???????E?c?Y?L,?????]???????4?????/??!????m?]?????4???? ;????q;,?????8?mCRecordset??????(scroll)????,??MoveFirst(), ;MoveNext(),MovePrev(),MoveLast()??,???????????/?C????????it???]is ;??????!]???????B?H???Bl0IsBOF(),IsEOF()?mq??)?f?u?*?????l???? ;???:?B?-l0

    ;??????!?qh???S???i??(Delete),????(AddNew)?????1(Edit),q??Q ;?6?TqK:

    ;if(m-recset.CanUpdate())/*?u?*?6??!??1*/

    ;{

    ;if(m-db.CanTransact())/*?u?*?u?2it??is?4?C*/ ;{

    ;m-db.BeginTrans();

    ;m-recset.AddNew();

    ;/*!??1?????????/*/

    ;...

    ;m-recset.Update();

    ;m-db.CommitTrans();

    ;if(catcherror)

;m-db.RollBack();

    ;}

    ;}

    ;??q?AddNew??Edit,!??1?????????Lq??????8?m????Update(), ;?*?e?????Cqy?+,?HDelete??!??eqO?????[?????/!??1???8?mUpdate ;()l0

    ;q&????CDatabase????qb?????uODBCqK!?????????!????????. ;?H??!???it??is?4?C????,???mBeginTrans??CommitTransq<???????? ;!??1????????q?!??0?3,???n??????RoolBack?????O?=????!??1l0 ;?m?n?m?g????!??m??,??q?qb????????q????nqb?m?g???nqbq??? ;????,qO?H??q??????H??!??1???H????????l0ODBC??!?q?q)?????? ;?????????H???K?P(?mm-recset.Open????q;?I??),it???2is??(snapshot) ;?????2??(dynaset)l0?]?S?uq??????2?????????E,???????LqO!n?1??, ;??q???????????????/?i???B,qO?????f???m?g??!??1,?????8?mq? ;Requery????????l0?L?S?uq??????2?????????E,?????B?f???m?g?=!? ;??!??1?????????l???Eq;??(???Pq????mRequery????),q?!??2???? ;qL?????????H??l0?m???mq;,???1??????????!??m??q??????Gl0 ;q?l2??????

    ;q?q?q&??????q??T??,ODBC???m?????6?C??!?!????q&Visual ;C++q;??AppWizard??ClassWizard?????c?Y?}??q??2????,????q?qb ;??????,?c?Yq?qbCRecordset????,?+??????q?l0

    ;???m?T?????????????????4?C?HqO???1????????????,???B,?? ;q?qbqLODBC?N??????CRecordView,?uq?qb??????CWnd???-?c??, ;?????mCRecordsetq&,?????????i???????????-?K????,??q?????qT ;q?qO??q??ml0

    ;[?,q??B??:????]

    ;r?

    ;r?IT???u????r?

    ;r?

    ;??

    ;63

    ;

Report this document

For any questions or suggestions please email
cust-service@docsford.com