《數(shù)據(jù)庫技術(shù)及應(yīng)用》實(shí)驗(yàn)報告_第1頁
《數(shù)據(jù)庫技術(shù)及應(yīng)用》實(shí)驗(yàn)報告_第2頁
《數(shù)據(jù)庫技術(shù)及應(yīng)用》實(shí)驗(yàn)報告_第3頁
《數(shù)據(jù)庫技術(shù)及應(yīng)用》實(shí)驗(yàn)報告_第4頁
《數(shù)據(jù)庫技術(shù)及應(yīng)用》實(shí)驗(yàn)報告_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、數(shù)據(jù)庫技術(shù)及應(yīng)用實(shí)驗(yàn)報告 題目:實(shí)驗(yàn)3嵌入式sql|姓名 |日期實(shí)驗(yàn)環(huán)境:microsoft visual c+ 6.0, microsoft sql server 2005實(shí)驗(yàn)內(nèi)容與完成情況: 實(shí)驗(yàn)內(nèi)容:在visual studio c+環(huán)境中通過odbc實(shí)現(xiàn)與實(shí)驗(yàn)1建立的數(shù)據(jù)庫stumanagement的互 聯(lián),進(jìn)行實(shí)驗(yàn)要求的各種操作,關(guān)系模式和數(shù)據(jù)的操作均通過應(yīng)用程序界面完成; 根據(jù)以下要求認(rèn)真進(jìn)行實(shí)驗(yàn),記錄所有的實(shí)驗(yàn)用例,填寫實(shí)驗(yàn)報告。1 數(shù)據(jù)庫連接1.1通過odbc實(shí)現(xiàn)與實(shí)驗(yàn)1數(shù)據(jù)庫互聯(lián);2 關(guān)系模式操作2.1創(chuàng)建1個基本表,并插入2行數(shù)據(jù);2.2修改及刪除基本表;3.數(shù)據(jù)操作:數(shù)據(jù)

2、查詢操作(注:對于實(shí)驗(yàn)要求的查詢種類,選擇1種實(shí)現(xiàn)即可);3.2數(shù)據(jù)修改操作;3.3數(shù)據(jù)刪除操作;3.4界面執(zhí)行sql語句操作(注:用戶通過界面輸入sql語句,應(yīng)用程序執(zhí)行該語句,對數(shù)據(jù) 庫進(jìn)行操作); 界面要求:查詢結(jié)果的多行顯示(至少支持5行以上查詢結(jié)果的顯示);界面美觀,操作簡單。實(shí)驗(yàn)過程:1. 通過odbc實(shí)現(xiàn)與實(shí)驗(yàn)1數(shù)據(jù)庫互聯(lián);在odbc應(yīng)用程序中,應(yīng)用程序要訪問一個數(shù)據(jù)庫,首先必須用odbc管理器注冊一 個數(shù)據(jù)源,建立起odbc與具體數(shù)據(jù)庫的聯(lián)系。只有在建立了連接之后才可以進(jìn)行對數(shù)據(jù) 源的操作,進(jìn)而操作數(shù)據(jù)庫。下面是注冊數(shù)據(jù)源的操作:打開odbc數(shù)據(jù)庫管理器g odbc 站源苜理器

3、用戶® 系統(tǒng)dsn 文件dsn驅(qū)動程序|跟蹤|連搬&關(guān)于 用戶數(shù)據(jù)源on:名稱嶇動程序microsoftaccessdbasedriver(.ddbase filesexctlfilesmicrosoftexceldriver(.xlsz.xms access database microsoft access driver (.mdb, . 學(xué)生信息sql strvtr添加叫二 刪除站illa躅®息。用1 碇 1 翊 應(yīng)用3 k幫助在“odbc數(shù)據(jù)源管理器”對話框中,單擊“添加”按鈕,彈出創(chuàng)建新數(shù)據(jù)源對話框,此 處選擇sql server為數(shù)據(jù)源驅(qū)動程序,如下圖。

4、創(chuàng)建新數(shù)據(jù)海區(qū)|選擇您想為其安裝數(shù)據(jù)源的呃動程序$)名稱microsoft mi crosoft mi crosoft microsoft mi crosoft microsoft microsoftmicrosoftfoxpro vfp driver (. dbf) odbc for oracleparadox driver (. db )paradox-tre 1 ber (*. db ) text driver (. txt; . csv) texttreiber (. txt; *. csv) visual foxpro drivervisual foxpro-treibersql n

5、ative clientsql server上一步d)芫成 i 取消 i 單擊“完成”按鈕后,彈出創(chuàng)建到sql server的新的數(shù)據(jù)源。如下圖。"更改默認(rèn)的教據(jù)庫為an : stufaan&geme&t匚附加數(shù)據(jù)庫文件名00: 叼甘定義的sql語句創(chuàng)建臨時存儲過程,并刪除該存儲過程只有當(dāng)斷開時(0)。o當(dāng)斷開時和連結(jié)時同樣適用。 回使用ansi弓|用的標(biāo)識苻(u)。 0使用ansi的空值、填充及警告m。若主sql server不可用,請使用故障轉(zhuǎn)移sql server (f)o上一步©)念一步00 取消 i 匚幫助更改sql server系統(tǒng)消患的語盲為(

6、c):simplified chinese0對數(shù)據(jù)使用強(qiáng)大的加密a)回執(zhí)行寧符數(shù)據(jù)詡譯tn當(dāng)輸出貨幣、數(shù)寧、日期和時間時,請使用區(qū)域設(shè)養(yǎng)。將長時間運(yùn)行的查詢保存到日志文件(s):c:utr天i|appbfl»ca打pqvzby.up(r).長查®時間(奎秒1): 300c0將odbc驅(qū)動程序統(tǒng)計記錄到日志文件(0)|c:'users'矢道appdatlocaltgpstats. l0 瀏覽儈).|上一步0) | 就 | 則匚幫助成功建立數(shù)據(jù)源odbc數(shù)潺滾吉理器 ,用戶吧n系統(tǒng)dsn i文件dsn驅(qū)動程庫跟蹤連接迪l關(guān)于用戶數(shù)擴(kuò):原an:名稱驅(qū)動程序dbas

7、e filesexcel filesms access dtiabase學(xué)生信息microsoft access dbase driver (.c microsoft excel driver ( xls . > microsoft access driver (». mdb# . sql server2. 創(chuàng)建單文檔應(yīng)用程序1)啟動visual c+6.0,選擇file|new,彈出new對話框,選擇projects標(biāo)簽,然后再列 表中選中選擇mfc app wizardexej選項(xiàng),在"project namen文本框中輸入工程文件名(根據(jù)需耍自己確定),在“l(fā)o

8、cation"中指定應(yīng)用文件創(chuàng)建的位置,如下圖所示:文件 工程|工作區(qū)|其它文檔|qatl com appwizard ejciuster resource type wizardhscustom appwizarddatabase project devstudio adddn wizard extended stored proc wizard isapi extension wizardj makefilemfc activex controlwizard)mfc appwizard (dll) |mfc appwizard (exej嚴(yán)程名稱(hl:lianxiz奔置囹:|d

9、:learningvc6.0myprojectslia 討jsinew database wizardutility project3win32 application2win32 console application 馬 win32 dynamiolink library win32 static librarya創(chuàng)建新的工作空間ibj 添加到當(dāng)前工作空間回 廠從ii于b3:平臺10:“win32確定|取消|單擊確定,選擇單文檔mfc應(yīng)屋壇序向?qū)Р叫Q1您要創(chuàng)建的應(yīng)用程序類型是:a單文檔s)多畫文檔基本對話框口&文檔隆看體系結(jié)構(gòu)支持(v)您的資源使用的語言是:|中文簡體,中國appw

10、zchs.dll)上一步下一步完成取消您要包含數(shù)據(jù)庫嗎?okg odbc:r dao:生信息cancelr ole db:select ole db datasource否標(biāo)題文件e查看數(shù)據(jù)庫不使用文件支持 廣查看數(shù)據(jù)庫使用文件支持如果您要包含數(shù)據(jù)庫視圖,就必須選擇數(shù)據(jù)源.數(shù)據(jù)源沒有選定數(shù)據(jù)源.上一步i下一步 i 完成 i 取消點(diǎn)擊數(shù)據(jù)源,按鈕,彈出database options對話框如下圖所示,在odbc的下拉列 表中選擇學(xué)生信息數(shù)據(jù)源。database optionsdatasourcerecordset typesnapshot 廠 dynasettableadvancedf dete

11、ct dirty columns單擊ok,彈11) select database tables對話框,如下圖所示,選擇自己要鏈接的表s。cancelselect database tablesdbo.sdbo.teachers information_schemacheck_constfw information schema.column domaih單擊ok,單擊next按鈕,這一步屮選擇文檔類型為容器類型,如下圖所示。mfc應(yīng)用程序向?qū)Р角?共6步您要使用什么樣的復(fù)合文檔支持?(dcontainer沒有不需要e容器微型展務(wù)器完整展務(wù)器容器和展務(wù)器廠廠活動文檔容器您要支持復(fù)合文件嗎?q是

12、m否d您還要包含其他支持嗎?廠自動5巨 activex 控件(r)上_步 i 下一步 i完成|取消單擊next,之后都是默認(rèn),單擊finish完成。到此初步的工程已經(jīng)建好,下面進(jìn)行界 面的設(shè)計。3. 新建界面按鈕在項(xiàng)目工作窗口屮選擇resourceview頁面,雙擊menu屮的idd_lianxi2_form, 彈岀文檔模板和控件工具欄,構(gòu)建界面如下圖:學(xué)生信建系統(tǒng)請輸入squ音句:11血行|請輸入學(xué)生信息:阿添加 | 刪除 | 修改 | 主健查詢| 阿醬入學(xué)號來的攝作董詢|壹詢結(jié)康如下:將學(xué)生信息系統(tǒng)部分的edit box的id分別改為idc_id_edit> idc_name_edi

13、t>idc_age_edit、idc_dept_edit> idc_checkname。將按鈕改為 id 改為idc_add、 idc_modh idc_del、idc_check4. 添加新類crecordsetadd:在工具欄上選擇insert|new class,添加一個新類crecordset add,如下圖所示:類的類型(t): i mfc class確定取消 iname:|crecordsetaddfile name:base class:dialog id:recordsetaddl .cppchange.crecordseti he base class does

14、not require a dialog resource.automationa noneq automationc createable by type id: |lianxi2.recordsetaddthe base class does not support automation.單擊ok,彈出database options對話框,如圖所示,同樣的選擇數(shù)據(jù)源“學(xué)生信息”后, 單擊ok按鈕,彈出select database tables對話框,選擇表s,單擊ok5. 數(shù)據(jù)的顯示在crecordsetadd中添加四個成員變量如下所示:cstring m_sno;cstring m_

15、sname;cstring m_sage;cstring m_sdept;同時其成員函數(shù)dofieldexchange如卜:void crecordsetadd:dofieldexchange(cfieldexchange* pfx)/afx_field_map(crecordsetadd) pfx->setfieldtype(cfieldexchange:outputcolumn);rfx_text(pfx, _t(”sno”),m_sno);rfx_text(pfx, _t(nsnameh), m_sname);rfxnt(pfx, _t(”sage”),m_sage);rfx_te

16、xt(pfx, _t(”sdept”),m_sdept);/afx_field_map即采用了 rfx機(jī)制實(shí)現(xiàn)了數(shù)據(jù)的交換。在clianxi2view:dodataexchange ()函數(shù)中添加代碼如下所示: void clianxi2view: dodataexchange(cdataexchange* pdx)crecordview:dodataexchange(pdx);/afx_data_map(clianxi2view)ddx_text(pdx, idc_edid_query, m_strquery);ddx_text(pdx, idc_sql_edit, m_sql);ddx_f

17、ieldtext(pdx, idc_edit1, m_pset->m_sno, m_pset);ddx_fieldtext(pdx, idc_edit2, m_pset->m_sname, m_pset);ddx_fieldtext(pdx, idc_edit4, m_pset->m_sdept, m_pset); ddx_fieldtext(pdx, idc_edit3, m_pset->m_sage, m_pset); afx_data_map 這樣就實(shí)現(xiàn)了數(shù)據(jù)的顯示問題。點(diǎn)擊界面上的紅色圓圈里的翻頁按鈕,可以逐個杳看記錄或杳看第一頁、最后頁的記錄:§3無

18、標(biāo)題iianxi2文件(f)編輯(e)記錄(r)m(v)耕助(h)6. “添加”的實(shí)現(xiàn):為了添加記錄,添加一個對話框資源:在項(xiàng)目工作去窗口中選擇resourceview頁面,右鍵單擊dialog選擇插入dialog,則添加了 一個對話框,為其添加四個edit box,其id分別為idc_id、idc_name、idc_age、 idc.deptoboject:lianxizclass name:|caddnewadd class. d:t.lianxi2addnew.k d:v.ananxi2addnew.cppadd variable.control ids:cstringcstring c

19、string cstringmemberdelete variableidc agem ageidcdept idcjd idc_name idcancelm_dept md m nameupdate columnsbind allmfc classwizardmessage maps member variables automation activex events class infoidok7. 實(shí)現(xiàn)添加功能的函數(shù)在主對話框中,即在resourceview頁面中,雙擊idd_l1anxi2_form,出現(xiàn)己經(jīng)設(shè) 計好的主對話框后,雙擊添加按鈕,出現(xiàn)對話框如下:單擊ok,為英添加函數(shù)如下

20、所示:void clianxi2view:onadd()/ todo: add your control notification handler code hereupdatedata();caddnew dig;cstring str;cstring strl;cdatabase db;if (idok=dlg.domodal()trystrl .format("insertintos(sno,sname,sage,sdept)values('%s'%s,'%s'/%s')",dlg.mi_id ,dlg.m_name,dlg.m

21、_age,dlg.m_dept);db.open(“學(xué)生信息“);db.executesql(str 1);catch(cdbexception *e)afxmessagebox(e->m_strerror);return;str.format("添加%s成功! ",dlg.m_name);messagebox(str,null,mb_ok|mbjconlnformatlon);m_pset->m_sno = dlg.m_id ; m_pset->m_sname = dlg.m_name; m_pset->m_sage =dlg.m_age; m_p

22、set->m_sdept = dlg.m_dept; updatedata(false);執(zhí)行結(jié)果:點(diǎn)擊添加按鈕,彈出對話框,填寫信息如下:學(xué)生信息學(xué)號 12345姓名張三取消年齡 20確定點(diǎn)擊確定按鈕,iianxi2添加進(jìn)晰!被添加的記錄在界面上成功顯示0 無- iianxi2文件(f)蜩(e)記錄(r)査v) 1v助(h)學(xué)生信愿系統(tǒng)姓名 陰三年齡20院系颶|匚嗣二|刪除| 修改|主鍵查詢|(輸入學(xué)號)8. 實(shí)現(xiàn)刪除功能的函數(shù)void clianxi2view:ondel()/ todo: add your control notification handler code here

23、/ caddnew dig;cdatabase db;trycstring str;crecordsetadd m_pdatabase;if (m_pdatabase.isopen()m_pdatabase.close();str.format("刪除記錄%$成功! ",m_pset->m_sname); m_pdatabase.open(crecordset:snapshot,null,crecordset:none); crecordsetstatus status; /cl m_pset->getstatus(status); /cl m_pdatabas

24、e.delete();if (! m_pdatabase.iseof()m_pdatabase.movelast();elsem_pdatabase.setfieldnull(null);if (m_pdatabase.isopen() m_pdatabase.close();m_pset->requery();updatedata(false);messagebox(str,null,mb_ok|mbconinformation); ) catch (cdbexception* e)afxmessagebox(e->m_strerror);return;)執(zhí)行結(jié)果如下:刪除成功,

25、界而顯示其他記錄。學(xué)生tt息系統(tǒng)學(xué)號200215121姓名庚系i sy9. 實(shí)現(xiàn)修改功能的函數(shù) void clianxi2view:onmodi()/ todo: add your control notification handler code here updatedata();caddnew dig;cstring str;cstring strl;cdatabase db;if (ldok=dlg.domodal()wherestrl.format(nupdate s set sname=,%ssage=l%ssdept=,%slsno=,%sm,dlg.m_name,dlg-rn_

26、age,dlg.m_dept,dlg<m _id);db.open(h學(xué)生信息”);db.executesql(strl);catch(cdbexception *e)afxmessagebox(e->m_strerror);return;str.format("修改%s成功! h,dlg.m_name);messagebox(str,null,mb_ok|mb_iconinformation); m_pset->m_sname = dlg.m_name;m_pset->m_sage =dlg.m_age; m_pset->m_sdept = dlg.m

27、_dept;updatedata(false);執(zhí)行結(jié)果如下:修改前學(xué)生ft息系統(tǒng) 學(xué)號 姓名 年齡 院系修改i主鍵查詢(輸入學(xué)號點(diǎn)擊修改按鈕,彈出對話框,填寫信息學(xué)生信亙表mg學(xué)生信息學(xué)號 1姓名 b年齡b院系b確定取消i修改結(jié)果:學(xué)生信息系統(tǒng)(學(xué)號 f1姓名年齡除系lb主鍵重詢| (si入學(xué)號)sqi執(zhí)行済輯入sql語句:查詢i刪除 i saceio.為査詢添加函數(shù)void clianxi2view:oncheck()/ todo: add your control notification handler code here updatedata();cdatabase db;db.op

28、en(n學(xué)生信息”);cstring str;m_checkname.trirnleft();if (m_checkname.isempty()messagebox(”要查詢的學(xué)號不能為空! ”);return;crecordset recset(&db);cstring strsql;strsql.formatc'select * from s where sno=,%s,',m_checkname); 執(zhí)行的 sql 語 句打開查詢結(jié)果集recset.open(crecordset: forwardonly,strsql,crecordset:readonly);i

29、f(recset.iseof() /查詢結(jié)果集為空messagebox("沒有查到你要找的學(xué)生記錄! ”);elsemessagebox("查詢成功! ”);cstring temp 1 ,temp2,temp4;cstring temp3;recset.getfieldvalue("sno",templ); i*ecset.getfieldvalue("sname",temp2);recset.getfieldvalue(hsage",temp3);recset.getfieldvalue(nsdepth,temp4);/

30、(int)(lpctstr)m_pset->m_sno = tempi ; m_pset->m_sname = temp2; m_pset->m_sage =temp3; m_pset->m_sdept = temp4;if (! m_pset->iseof()updatedata(false);recset.close();i執(zhí)行結(jié)果如下:輸入查詢信息:學(xué)生信患系統(tǒng)學(xué)號p姓名年齡b院系b添加 i刪除 i修改 i主鍵查詢|200215121|輸入學(xué)號)點(diǎn)擊主鍵查詢后:學(xué)生信息系統(tǒng)學(xué)號|200215121姓名1李勇年齡|20院系|cs添加 |團(tuán)除 |愀 |i 匚越e

31、e 緘i|200215121(輸入學(xué)號11. 數(shù)據(jù)庫記錄顯示在mainfrm. cpp中,將indicators數(shù)組修改成如下代碼: static uint indicators=id.separator,id_separator, status line indicatorid_indicator_caps,idjndicator.num,id_indicator_scrl,;在 mainfrm.h 中,將 m_wndstatusbar 改為 public: public: / control bar embedded memberscstatusbar m_wndstatusbar;cto

32、olbar m_wndtoolbar;在"建立類向?qū)А敝?選中oncommand,點(diǎn)擊add function如下圖:mfc classwizardmessage mapsmember variablesautomation activex events | class info ibroject:ilianxi2class name:| |clianxi2viewd:v.ahanxi2lianxi2view.h, d:.aiianxi2lianxi2view.cppobject ids:messages:clianxi2viewid app about idididididapp_

33、exit cancel_edit_cntr edit_copy edit_cutedit pastemember functions:ww0wwonchaxun oncheckoncommandondc_chaxun:bn_clicked on idc check:bn clickedoncreatetalbebuttcondc_cre3tetalbebutton1:bn_clicked ondelon idc del:bn clickeddescription: processes the message map for command messages在該函數(shù)中添加代碼:bool clia

34、nxi2view:oncommand(wparam w param, lparam i param) / todo: add your specialized code here and/or call the base classcstring str;cmainframe *pframe=(cmainframe*)afxgetapp()->m_pmainwnd;cstatusbar*pstatus=&pframe->m_wnclstatusba;if (pstatus)crecordsetstatus rstatus;m_pset->getstatus(rstat

35、us);str.format(h 當(dāng) 前 記 錄:%d/錄:%dnj +rstatus.m_lcurrentrecord,m_pset->getrecordcount();pstatus->setpanetext( 1 ,str);return crecordview:oncommand(wparam, iparam);執(zhí)行結(jié)果如圖紅色部分:學(xué)生信息系統(tǒng)學(xué)號姓名年齡院系)20021512215'cs添加1刪除1修改1主謹(jǐn)杳詢1i1(輸入學(xué)號)執(zhí)行請輸入學(xué)生信息:查詢查詢結(jié)果如下:sno1 sname| sage<nr卜sqil 行請輸入sql語句:12新建表。添加按鈕

36、”新建表二id改為idc.createtalbebuttonl,函數(shù)如下:void clianxi2view:oncreatetalbebutton 1()/ todo: add your control notification handler code herecdatabase db;/if (!sqlconfigdatasource(null,odbc_add_dsn,hsql server”, “dsn 二學(xué)生信息”); trydb.open(”學(xué)生信息”);db.executesql(” createtableteachers(teacherldchar(4)',h,tea

37、chername char(10),h,course char(10)門;catch (cdbexception* e)afxmessagebox(e->m_strerror);return;messagebox("新建表成功!");執(zhí)行結(jié)杲如下:點(diǎn)擊按鈕前,數(shù)據(jù)庫中的表如下圖:stumanageme nt (£ 一i站庫關(guān)系圖 曰匚口田l3漿統(tǒng)表(s dbo.sb _j視圖點(diǎn)擊新建表按鈕:打開數(shù)據(jù)庫進(jìn)行查看: (j stumanagement ffi j加庫關(guān)索圖teacher idteacher namecourse米nullnullnull曰c3衰&#

38、174;二矣統(tǒng)表 £ 3 dbo.s s) 田視圖dbo.teachers13刪除表添加按鈕“刪除表”,id改為idc_delnewtalbebuttonc函數(shù)代碼如下: void clianxi2view:ondelnewtalbebutton()/ todo: add your control notification handler code herecdatabase db;trydb.open(n學(xué)生信息“);db.executesqlc'drop table teachers”); m_xiugaiflag=o;catch(cdbexception *e)afxm

39、essagebox(e->m_strerror); return;)messageboxc*刪除表成功! ”);執(zhí)行結(jié)果如下:數(shù)據(jù)庫屮c沒有teachers表e lj stumanagement曰匚ee) lj談淒 田二 dbo.ss)匚視圖14添加數(shù)據(jù)添加了一個對話框,為其添加三個edit box,其id分別為idc_teacherid、idc_teachernamea idc_coursc。在類向?qū)Ю餅槠涮砑觕string類型的變量 m_toachorid, m_toachornamo, m_course.為其建立類cshujunow,該類繼承自類cdialogo教師信息確定取消i教

40、師id悔輯教師編輯課程編輯再添加一個對話框,為其添加四個edit box,其id分別為idcteacherld.idc_teachernameidc_course> idc_teacherage在類向?qū)Ю餅槠涮砑觕string類型的變 量m teacherid, m teachername, in course, m teacherage.為其建立類cshljunew2,該類繼 承自類cdialogcn 教 iw5.e«2設(shè)置一個xiugaiflag標(biāo)志,當(dāng)表被修改時,xiugaiflag標(biāo)志置為1。否則,置為0。 當(dāng)xiugaiflag=0時調(diào)用教師信息表1, xiugaif

41、lag=l時調(diào)用教師信息表2 添加按鈕“添加數(shù)據(jù)”,id改為idc_addnewtablebuttono函數(shù)代碼如下: void clianxi2view:onaddnewtablebutton()/ todo: add your control notification handler code herecshujunew dig;cshujunew2 dlg2;cstring str;cstring strl;cdatabase db;if(m_xiugaiflag=o)if (idok=dlg.domodal()trydb.open(h學(xué)生信息j;str 1 .format("

42、 insertinto teachers(teacherid,teachername,course)values('%s',%s7%s,)",dlg.m_teacherid,dlg.m_teachername,dlg.ni_course);db.executesql(strl);catch (cdbexception* e)e->reporterror(); return;messagebox("添加數(shù)據(jù)成功! ”);else if(m_xiugaiflag= 1)if (idok=dlg2.domodal()trydb.open(”學(xué)生信息”);st

43、rl.formatc'insertintoteachers(teacherid,teachername,course,teacherage)values('%s','%s7%s',%s,)",dlg2.m_teacherid,dlg2.m_teachemame,dlg2.m_course,dlg2.m_teac herage);db.executesql(str 1);catch (cdbexception* e)e->reporterror();return;messagebox("添加數(shù)據(jù)成功! ”);執(zhí)行結(jié)果如下:點(diǎn)擊添加

44、數(shù)據(jù)按鈕,填寫教師信息表收師信息襲1匕空創(chuàng)教師信息確定教師id教師|a取消點(diǎn)擊確泄,查看數(shù)據(jù)庫/ 表 dbo.teachersasteacher idteacher namecourse1aa米nullnuunuu點(diǎn)擊修改表后,再點(diǎn)擊添加數(shù)據(jù)按鈕,確定教師id教師課程年齡查看數(shù)據(jù)庫表 dbo.teachersi廠teacherldteachernamecourseteacherage1aanull2|qq40米 nullnullnullnullii15.修改表添加按鈕“修改表”,id修改為idc.modbutton,設(shè)置一個xiugaiflag標(biāo)志,當(dāng)表被修改時,xiugaiflag標(biāo)志置為1

45、。否則,置為0 函數(shù)代碼如下:void clianxi2view:onmodbutton()/ todo: add your control notification handler code herecdatabase db;trydb.open(n學(xué)生信息”);db.executesql("alter table teachers add teacherage inf'); m_xiiigaiflag=l;)catch(cdbexception *e)afxmessagebox(e->m_strerror); return;messagebox(,r修改表成功! ”

46、);執(zhí)行結(jié)果如下: 修改前:if dbo.teachers眄teacher idteacher namecourse二 ji1aa米nuunuunull點(diǎn)擊修改表按鈕,teachers表多了一列,名為teacherage;/ 表-dbo.teachersteacherldteachernamecourseteacher age 1aaeza楽nullnullnullnull16.按鈕查詢添加按鈕“查詢”,id改為idc_chaxun。添加編輯框,id改為idc_chaxunxinxi, 在類向?qū)у鵀槠涮砑幼兞縨_chaxunxinxi,類型為cstringo函數(shù)代碼如下:void clianx

47、i2view:0nchaxun()/ todo: add your control notification handler code hereupdatedata(true);clistctrl * list=(clistctrl*) getdlgitem(idc_jieguo);/(clistctrl&)getlistctrl(); list->modifystyle(null,lvs_report);list->setextendedstyle(lvs_ex_gridlines|lvs_ex_fullrowselect|lvs_ex_head erdragdrop|l

48、vs_ex_oneclickactivate);/list->deleteallitems();cdatabase db;db.open(“學(xué)生信息”);crecordset recset(&db);list->deletea llltems();cstring sqheditl;m_chaxu nxinxi.trimleft();if ( m_chaxunxinxi.isempty()afxmessagebox(hifi輸入學(xué)號、姓名、年齡或?qū)W歷! “);return;sqlformatc1 select * from s where (sno= %sf) or (sna

49、me= %s') or (sage=,%s) or (sdept=,%s,), m_chaxunxinxi5m_chaxunxinxi,m_chaxunxinxi,m_chaxunxinxi);recset.open(crecordset:forwardonly,sql,crecordset:readonly);int ii;while(!recset.iseof()cstring tempi ,temp2,temp3,temp4;recset.getfieldvalue(msno,temp 1);recset. getfieldvalue("sname 役 temp2);r

50、ecset.getfieldvalue(nsage,temp3); recset.getfieldvalue(hsdept,temp4); ii=list->insertitem(o,n");list->setitemtext(iia temp 1); list->setitemtext(ii, 1, temp2);list->setitemtext(ii,2, temp3); list->setitemtext(ii3, temp4);u pdatedata( fal se);ii+;recset.movenext();recset.close();m

51、essagebox(n查詢成功! ! ! ”);db.close();執(zhí)行結(jié)果如下:查詢is系的學(xué)生信息結(jié)果如下請輸入學(xué)生信息:戶查詢結(jié)果如下:snoi snamei sagei sdept民成東立8 8 9isisis20021512520021512415126iii17.界面執(zhí)行sql添加編輯框,id改為idc_sql_edit,在類向?qū)Ю餅槠涮砑幼兞縨_sqledit,類型為cstringo 添加按鈕“執(zhí)行”,id改為idc_selecto執(zhí)行操作語句前先初始化列表,函數(shù)操作為void clianxi2view: :oninitialupdate()m_pset = & get

52、document()->m_lianxi2set;crecordview:onlnitialupdate();getparentframe()->recalclayout();resizeparenttofit();/ todo: remove this code when final selection model code is written m_pselection 二 null;/ initialize selectionwhile (!m_pset->iseof()m_pset->movenext();m_pset->getrecordcount();

53、m_pset->movefirst();updatedata(true);clistctrl * list=(clistctrl*) getdlgitem(idc_jieguo);/(clistctrl&)getlistctrl(); list->modifystyle(null,lvs_report);list->setextendedstyle(lvs_ex_gridlines|lvs_ex_fullrowselect|lvs_ex_head erdragdrop|lvs_ex_onecl1ckact1vate);list->insertcolumn(0,"snoh);list->insertcolumn( 1 ,"sname"); list->insertcolumn(2,"sage");list->lnsertcolumn(3,hsdept");list->setcolumnwidth(0,80);list->setcolumnwidth(l ,80);list->setcolumnwid

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論