第一篇:數(shù)據(jù)庫編程專業(yè)英文求職信
Dear leaders:
Hello!
I am a forthcoming XXXX University XX in XX graduate students, the school is a computer professional.University for four years, I study hard, the outstanding, have been awarded scholarships.Mentorship in the strict lessons and individual efforts, I have a solid foundation of knowledge.In terms of software, systems have C language, data structure, power Builder, database theory, assembly language, software engineering and object-oriented, such as DELpHI and VC have a certain understanding of Windows programming.I also had extra-curricular learning VB, VF programming, ASp and SQL Server dynamic pages, such as web-based database programming language.Has been prepared by an independent professional database management system.In terms of hardware, through its participation in single-chip design, assembly of the radio, network planning and management projects and the formation of such practice, I have a computer and the working principle of the principle of computer network technology.Into the school since, I take full advantage of a wide range of spare time to participate in social practice.College information in our school computer lab to work two years, not only the professional skills I have been raised, but also the management and organization, I will be able to play and further training, leadership and teachers received recognition and praise.Moreover, science and technology in Europe and Asia have some of the company's work experience, I have some marketing experience and social experience, and outstanding performance.In addition, at school, I also made home, the practice of social surveys and other social activities, and accumulated a wealth of practical experience.If fortunate enough to join, I can dedicated to your company's software development, or at any time in accordance with the needs of the company is committed to a work and learning.“Soon Come, come against, I dust free” is my motto;“immersive an abyss, treading on thin ice” is the attitude of my work;“sincere, and trustworthy” is my most prominent feature;an open mind has given me many friends.Smart-minded, creative thinking, and pioneering spirit of tenacity, coupled with sophisticated professional skills, I believe I am the best choice for you.please give me a chance, I will also you to eye-catching glory.Thank you for your patience in reading my cover letter, such as the need for detailed information, please contact me.敬候good news!
第二篇:計(jì)算機(jī)軟件編程專業(yè)求職信
尊敬的HR:
您好!
本人欲申請(qǐng)貴公司外貿(mào)業(yè)務(wù)員一職,所以冒昧寫了一封求職信,近段時(shí)間從事過兩份與專業(yè)相關(guān)聯(lián)的工作,仍舊發(fā)現(xiàn)自己對(duì)外貿(mào)行業(yè)的熱愛和興趣,我想每個(gè)人都有為夢(mèng)想和理想去熱愛努力追求并為之努力付出,并從中獲得人生的樂趣。
斯于2010年7月畢業(yè)于福建師范大學(xué)信息技術(shù)學(xué)院。我對(duì)外貿(mào)非常感興趣,從大三開始我就打算以后畢業(yè)后從事進(jìn)出口業(yè)務(wù)。我了解這對(duì)于我來說并不是一件非常容易的事情,因?yàn)槲业膶I(yè)既不是國際貿(mào)易專業(yè),也不是英語或其它外語專業(yè),而是計(jì)算機(jī)可視化軟件編程設(shè)計(jì),我也未曾有過外貿(mào)方面的工作經(jīng)驗(yàn)。但計(jì)算機(jī)專業(yè)的我從來都未停止過對(duì)互聯(lián)網(wǎng)和電子商務(wù)的了解。《羊皮卷》上的話一直鼓舞著我堅(jiān)持下去,“只要持之以恒,什么都可以做到”。我?guī)缀趺刻於紙?jiān)持學(xué)習(xí)商務(wù)英語,大量地聽,練習(xí)商務(wù)書信寫作和商務(wù)英語口語,學(xué)習(xí)國際貿(mào)易的基本知識(shí),熟悉進(jìn)出口的業(yè)務(wù)流程和貿(mào)易術(shù)語,單證等。另外,我也經(jīng)常上網(wǎng)通過msn和其它國家的網(wǎng)友用英語交流,發(fā)e-mail等,在這個(gè)過程中,我看到了自己的進(jìn)步,同時(shí)也體驗(yàn)到了充實(shí)的滿足感和樂趣。
我知道萬事開頭難,能夠進(jìn)入外貿(mào)行業(yè)這個(gè)門檻是我的第一步,相信有了我的第一步,我的第二步、第三步……我相信只要肯投入和學(xué)習(xí)就一定可以創(chuàng)造價(jià)值,不過這需要一個(gè)創(chuàng)造價(jià)值的平臺(tái),希望貴公司能給我這次機(jī)會(huì)。
承蒙審閱,深表感激。
此致
敬禮!
第三篇:英文專業(yè)求職信
英文專業(yè)求職信
英文專業(yè)求職信1
Dear company leader:
Hello!
First of all, I send you my warmest regards. Thank you for reading my cover letter.
I am XX university law school, majoring in law, 20xx graduating college graduates. In the comprehensive evaluation grade ranked No. x (the professional XX), majoring in curriculum of jurisprudence, constitutional law, civil law, criminal law, administrative law, civil procedure law, criminal procedure law and administrative procedure law, economic law, commercial law, economic law, intellectual property law, international law, international law, international economic law etc.. XX school year won the first class scholarship; XX school year two school scholarship, and in 20xx to XX points through the national judicial examination. Professional knowledge is strong, have necessary professional accomplishment. At the same time, English level is good, through CET-4 (XX) and CET-6 (XX). With computer skills, access to the national computer level, the national computer two (VF) certificate. The level of Putonghua test is first class.
I am able to keep good working condition and strong sense of responsibility. Have the spirit of learning, hard work. Optimistic personality, cheerful, positive, willing to help others, good at communication with people, with the spirit of cooperation. I sincerely hope to become a member of your company, so as to develop my special skills and work hand in hand with my colleagues. I will devote myself to the development of your company!
Wish you success in your work!
This
Salute!
英文專業(yè)求職信2
尊敬的領(lǐng)導(dǎo):
你好!請(qǐng)將麻煩。我來自湖北經(jīng)濟(jì)學(xué)院研究生。我很榮幸有機(jī)會(huì)給你看我的個(gè)人信息。在所有的社會(huì)中,為了找到符合自己專業(yè)和興趣的工作,實(shí)現(xiàn)自己的人生價(jià)值,所有的領(lǐng)導(dǎo)人自我推薦。
我們將自己的簡介如下:
我是學(xué)習(xí)酒店管理專業(yè)的大學(xué)生,我熱愛我的專業(yè)并為其投入了巨大的熱情和精力。在四年的大學(xué)生活,我學(xué)習(xí)內(nèi)容包括理論知識(shí)學(xué)習(xí)的專業(yè)技能知識(shí)。通過這些知識(shí)的學(xué)習(xí),我有這方面的知識(shí)有一定程度的理解和掌握,并有一定的實(shí)際操作能力和技術(shù)
在學(xué)校學(xué)習(xí),基本理論知識(shí),或?qū)嶋H操作技能,我把優(yōu)秀的結(jié)果。在學(xué)校除了學(xué)習(xí),我還積極參加社會(huì)實(shí)踐活動(dòng)。曾經(jīng)在XX學(xué)院參加“三下鄉(xiāng)”社會(huì)實(shí)踐活動(dòng)。被授予“優(yōu)秀積極分子”XX 5月到10月曾去法國學(xué)習(xí)西方飲食文化和法國的高星級(jí)酒店實(shí)踐,這樣我能掌握更多的西餐服務(wù)的標(biāo)準(zhǔn)和系統(tǒng)。能使用流利的法語和客人溝通。
我真誠地希望能夠你的酒店為了實(shí)現(xiàn)我的夢(mèng)想,你的`酒店給我的權(quán)力。同時(shí)也希望能夠你的酒店和精英之間的團(tuán)結(jié)與合作。相信可以使酒店以后的事業(yè)蒸蒸日上。如果我有幸加入到酒店,我肯定會(huì)努力的做我的工作。
英文專業(yè)求職信3
dear leaders:
hello! i am a aviation jiangxi vocational and technical college 09 students customs and international freight.
i learned from the online recruitment advertising your company wish to recruit a foreign dan zhengyuan, special liberty to write candidates. this is my candidate for the job an important cover letter.
six months later, i will jiangxi vocational and technical college 09 aviation customs and international freight professional school training. systematic study of the theory and practice of international trade documents, dan zhengyuan mastered the basic skills and knowledge, can work in the documents. “l(fā)earn to work at work, in learning learning to learn.” as college students, i focus on their abilities. optimism, perseverance, hard work is my beacon of hope in the rapids at the hoist the sail, brave the rapids in the highlighted character, is my life credo. so i put more enthusiasm among the new challenges, the impact toward higher goals.
will graduate in june next year. in school, i learn the system of international trade theory and practice, theory and practice of international trade documents, basic english, english writing, cargo science, writing, management, international trade practices, business communication and so on. with outstanding results. familiar with computer operation, and the systematic study of accounting, the accounting profession to master the basic skills and knowledge.
last year and this summer, i had two weeks training in a unit, accumulated some work experience. i like to trade dan zhengyuan this job, hoping to become a member of your company, and we make every effort to work together to promote the development of the company do a good job.
such as give me the opportunity to interview, i would be greatly honored.
英文專業(yè)求職信4
您好!
感謝您在百忙之中審閱我的求職申請(qǐng)。
入校以來,我堅(jiān)持刻苦學(xué)習(xí),通過四年的積累,擁有了作為一名跨世紀(jì)師范大學(xué)生應(yīng)該掌握的理論基礎(chǔ)知識(shí)和專業(yè)知識(shí)。在擔(dān)任班級(jí)干部期間,注重鍛煉自己的組織領(lǐng)導(dǎo)和協(xié)調(diào)合作的能力,積極熱情地開展工作,在同學(xué)中享有一定的威望。
同時(shí),我也利用課余時(shí)間加強(qiáng)對(duì)自己實(shí)踐能力的培養(yǎng),積極參加各種社團(tuán)活動(dòng),全方位充實(shí)自己。四年中,我一直在ELIC工作,通過和他們的語言交流,拓寬了自己的文化視野,提高了自己的英語運(yùn)用能力。我在東北師大附中實(shí)習(xí)期間,落落大方的教態(tài),明晰清楚的講解,認(rèn)真負(fù)責(zé)的態(tài)度獲得了指導(dǎo)老師和學(xué)生們的一致好評(píng)。
天行健,君子當(dāng)自強(qiáng)不息。我深信我會(huì)一步一個(gè)腳印走得更好!但我也明白自己的平凡,知道自己在各方面還需要進(jìn)一步提高。或許在貴校的求職者中我并不是最優(yōu)秀的,但我相信自己的綜合實(shí)力,更相信您的慧眼。
大學(xué)之道,止于至善。懇切盼望您詳考、慎慮,使我與貴校共同發(fā)展,求至善、創(chuàng)輝煌!
我的過去正是為貴校的發(fā)展準(zhǔn)備、積蓄;
我的未來正是為貴校奮斗、拼搏、奉獻(xiàn)。
英文專業(yè)求職信5
Dear leader,
Hello! First of all, I appreciate your reading my materials in your busy schedule.
I graduated from shandong university of traditional Chinese medicine of traditional Chinese medicine is professional, I don't want to enjoy “books to time square hate less” suffering, more don't want to be a “young don't work hard,” idle young, needy old useless, therefore, in the university life, to accumulate and medical knowledge, improve their various aspects ability. During this period, I have mastered a solid theoretical foundation and made full use of my spare time to participate in clinical practice, which will lay a solid foundation for future clinical practice. Through a large number of clinical practice, I have preliminarily possessed the quality of a medical worker, I believe that the strength of the education, I will realize my life value on the medical path. If knowledge make me have the courage to step into your threshold, to choose and accept you, so, in my own ability and dedication and enthusiasm to the work, combined with their own plasticity and the pursuit of better learning professional knowledge, I think I'll economy in applicants, and become a member of your company. “The machine will try to understand its dull, and the horse will ride and know its good will.” Maybe I am not the best, but I will keep trying. Don't seek a comfortable environment, but seek a chance to develop. I am confident that in my new job, I will be humble, steadfast, diligent and enterprising. I will soon be able to enter a new working environment, take on new roles and make satisfactory achievements.
Look forward to your good news, and wish your company a thriving business.
advance
salute
Sponsor: xx
Xx (date) (month) (year)
英文專業(yè)求職信6
尊敬的領(lǐng)導(dǎo):
您好!我是xx市第二職業(yè)高級(jí)中學(xué)會(huì)計(jì)專業(yè)班的學(xué)生,即將踏上社會(huì)的我對(duì)自己的職業(yè)生涯充滿了信心和期待,希望您能給我一個(gè)與貴公司合作的機(jī)會(huì),會(huì)計(jì)專業(yè)求職信。
現(xiàn)在的我首先想得到的是貴公司和社會(huì)對(duì)我的認(rèn)可,我認(rèn)為能展現(xiàn)自己的價(jià)值和取得更大的價(jià)值是我要努力的方向。只有得到他人的認(rèn)可,社會(huì)的認(rèn)可,自我的價(jià)值也就得到了肯定,這樣才能促使我更加有信心的投入到工作中,與貴公司一同向成功前進(jìn)。
在校時(shí),我學(xué)習(xí)了很多關(guān)于會(huì)計(jì)這一職業(yè)的課程,比如:會(huì)計(jì)電算化的知識(shí),基礎(chǔ)會(huì)計(jì)的課程,企業(yè)會(huì)計(jì)、財(cái)經(jīng)法規(guī)與會(huì)計(jì)職業(yè)道德、珠算、點(diǎn)鈔等,我們學(xué)校注重的是學(xué)生的職業(yè)技能和素質(zhì),所以我對(duì)于會(huì)計(jì)的賬務(wù)處理也很熟悉。在校時(shí),我們?cè)诶蠋煹南ば慕虒W(xué)下用金蝶7.5版財(cái)務(wù)軟件學(xué)習(xí)賬務(wù)處理,通過上機(jī)操作與運(yùn)用,我對(duì)于電算化處理賬務(wù)已經(jīng)能夠運(yùn)用自如。在學(xué)習(xí)的過程中,我也常會(huì)遇到問題,但只要認(rèn)真的去做,最終問題都被解決了。我希望也能用這種認(rèn)真的工作態(tài)度為貴公司效力。(后附有會(huì)計(jì)從業(yè)資格證書,辦公自動(dòng)化化初級(jí)證書等)
幾年的學(xué)校生活,我學(xué)會(huì)了不少東西,豐富了我對(duì)社會(huì)的了解,也鞏固了我的專業(yè)技能和知識(shí),我在校積極參加各種活動(dòng),學(xué)校組織的黨校培訓(xùn),校園絲綢文化節(jié),校運(yùn)會(huì),我也曾在這些活動(dòng)中取得較好成績,受到老師的表揚(yáng)。我還積極參加學(xué)生會(huì)的招生,因?yàn)槲蚁M谛F陂g能為學(xué)校做點(diǎn)事,這樣也能鍛煉我的管理能力,我喜歡體育,適當(dāng)?shù)倪\(yùn)動(dòng)既能放松心情又能強(qiáng)身健體,有一個(gè)健康的身體才能更好的工作。
我是真心想進(jìn)貴公司工作的,在工作中繼續(xù)不斷提升自我的工作能力,所謂理論與實(shí)踐相結(jié)合,我會(huì)向工作經(jīng)驗(yàn)資深的同事多請(qǐng)教,“取其精華,取其糟粕”。如果能與貴公司合作,我將無比榮幸,如若無此榮幸,請(qǐng)您指出我的不足之處,好讓我改進(jìn)自己的不足。
希望貴公司能夠錄用我,我必將好好努力。
在此祝貴公司生意興榮,事業(yè)蒸蒸日上!
此致
敬禮
英文專業(yè)求職信7
While studying at the school I was a member of the class publicity, creative and organized a “Premier Zhou footprints along the way forward” the signature of the 1000 activities of students, school teachers and students have been widely acclaimed.
I am well aware that as an economic category of students, the exchange of essential practice. Thus, in 98 years I joined the “soft science enthusiasts Jilin Engineering Association” in the Department of Market Research. As an assistant, I participated in the preparation of the visit and summed up with the “Evergreen Daily” cooperation “consumer survey of university students” and “computer at the university campus,” the research project, through the real data, correcting some of the people of the community college students is incorrect views caused great repercussions.
I firmly believe that to adapt to the needs of society as a complex human resources, into the community is essential to draw nutrients. 99 years in August to October, I am in the “Xiamen Overseas Chinese Electronics Co., Ltd.” in office has done a three-month long promotional Miss, the initial feeling of intense business competition, but also to understand the micro-see giant enterprises in China the status quo. In July the same year to 11-month period, I have a part-time “modern” market consulting company investigators, to “market research” has done a comprehensive, professional, deep understanding. These experiences for me into the community, involved in the operation of business and laid a good foundation.
I have perseverance character, love and respect their jobs, be able to endure hardship, to be bold, the work can獨(dú)擋一面, but also solidarity and cooperation.
My life philosophy is: “there is nothing.” I believe you chose me, it chose the pursuit of success. I would like to use their professional knowledge and wisdom for the development of your company to make modest!
英文專業(yè)求職信8
尊敬的領(lǐng)導(dǎo):
你好!
首先感謝您在百忙中抽時(shí)間來閱讀這封!我叫XX,現(xiàn)年16周歲,來自賀州,是藥劑專業(yè)09屆畢業(yè)生,畢業(yè)于XXX學(xué)校!我希望能得到您們的賞識(shí)與栽培,為了發(fā)揮自己的才能,特向朋友們自薦。在這里我不能向您們出示任何有權(quán)威的人士的推薦書來為我謀得職業(yè),也拿不出一累累的獲獎(jiǎng)證書來做我的籌碼,但我會(huì)用我所學(xué)的知識(shí)做為我的奠基石。如果說我有什么優(yōu)點(diǎn)的話,那就是我年輕,我有能力。雖然我沒有過什么藥營經(jīng)驗(yàn),我堅(jiān)信自己能做好每項(xiàng)事!
在校期間,我認(rèn)真學(xué)習(xí),努力做好本職工作,在班上身為一名副班長,更要有帶頭作用,紀(jì)律性要嚴(yán)謹(jǐn)。在社團(tuán),我是一名理事,安排人員值周,把每象工作安排得井井有序!積累了大量的工作經(jīng)驗(yàn),具有良好的身體素質(zhì)和心理素質(zhì)。幾年來我努力學(xué)習(xí)專業(yè)知識(shí)從各門課程的基礎(chǔ)知識(shí)出發(fā),技能操作規(guī)范。并熟悉了常用藥物的理化性質(zhì),藥理作用及劑型特點(diǎn),掌握了藥物的提取、合成、檢識(shí)等實(shí)驗(yàn)技能。
這為我今后奠定了良好基礎(chǔ),也取得良好成績。除此,我還自學(xué)了電腦方面的一些知識(shí),比如:電腦一般故障的排除和文字的處理與排除,制作圖片、表格等。作為一名當(dāng)代學(xué)生“服務(wù)社會(huì)”是我的職責(zé),“敬業(yè)”是我的人生信條,“年輕”“可塑性強(qiáng)”是我的資本。我將以飽滿的熱情,一絲不茍的態(tài)度迎接挑戰(zhàn)。“大道酬勤”是我的信念,“自強(qiáng)不息”是我的追求。我特在此冒昧自薦,如果能得到您們的青睞我一定會(huì)以不斷學(xué)習(xí)、積極進(jìn)取的精神,竭誠為您們服務(wù),做到鞠躬盡瘁。希望貴學(xué)校能給我一個(gè)發(fā)展的平臺(tái),我會(huì)好好珍惜它,并全力以赴,為實(shí)現(xiàn)自己的人生價(jià)值而奮斗,為貴學(xué)校的發(fā)展貢獻(xiàn)力量。
此致
敬禮
求職者:
20xx年9月27日
第四篇:專業(yè)英文求職信
專業(yè)英文求職信范文
four years as a senior clerk in sales department of the new world products company have,i believe,given me the experience to qualify for the job you advertised in thursday's newspaper.since 1981 i have been responsible for all office details in the administration of sales,including writing much of the
correspondence.in the course of my work,i have become familiar with the various sales territories,and have also in my spare time
experience of handling business problems other than my proper sphere.the years before i was employed at the new world,i was a
secretary for long brother,an accounting firm.there i became familiar with accounting terms and procedures.i was graduated at wah yan college, in june 1974.i am twenty-five years of age and single.i am leaving my present position because i can use my
capabilities more fully in a position with wider scope.my present employer knows of my ambition and is helping me to find a new place.may i see you at your office to tell you more about myself and show you just how well i can do the work you require.yours faithfully
第五篇:數(shù)據(jù)庫編程總結(jié)(推薦)
數(shù)據(jù)庫編程總結(jié)
當(dāng)前各種主流數(shù)據(jù)庫有很多,包括Oracle, MS SQL Server, Sybase, Informix, MySQL, DB2, Interbase / Firebird, PostgreSQL, SQLite, SAP/DB, TimesTen, MS ACCESS等等。數(shù)據(jù)庫編程是對(duì)數(shù)據(jù)庫的創(chuàng)建、讀寫等一列的操作。數(shù)據(jù)庫編程分為數(shù)據(jù)庫客戶端編程與數(shù)據(jù)庫服務(wù)器端編程。數(shù)據(jù)庫客戶端編程主要使用ODBC API、ADO、ADO.NET、OCI、OTL等方法;數(shù)據(jù)庫服務(wù)端編程主要使用OLE DB等方法。數(shù)據(jù)庫編程需要掌握一些訪問數(shù)據(jù)庫技術(shù)方法,還需要注意怎么設(shè)計(jì)高效的數(shù)據(jù)庫、數(shù)據(jù)庫管理與運(yùn)行的優(yōu)化、數(shù)據(jù)庫語句的優(yōu)化。
一、訪問數(shù)據(jù)庫技術(shù)方法
數(shù)據(jù)庫編程分為數(shù)據(jù)庫客戶端編程與數(shù)據(jù)庫服務(wù)器端編程。數(shù)據(jù)庫客戶端編程主要使用ODBC API、ADO、ADO.NET、OCI、OTL等方法;數(shù)據(jù)庫服務(wù)端編程主要使用OLE DB等方法。
1、幾種是數(shù)據(jù)庫訪問方法比較
ODBC
API是一種適合數(shù)據(jù)庫底層開發(fā)的編程方法,ODBC
API提供大量對(duì)數(shù)據(jù)源的操作,ODBC
API能夠靈活地操作游標(biāo),支持各種幫定選項(xiàng),在所有ODBC相關(guān)編程中,API編程具有最高的執(zhí)行速度。DAO提供了很好的數(shù)據(jù)庫編程的對(duì)象模型.但是,對(duì)數(shù)據(jù)庫的所有調(diào)用以及輸出的數(shù)據(jù)都必須通過Access/Jet數(shù)據(jù)庫引擎,這對(duì)于使用數(shù)據(jù)庫應(yīng)用程序,是嚴(yán)重的瓶頸。
OLE
DB提供了COM接口,與傳統(tǒng)的數(shù)據(jù)庫接口相比,有更好的健壯性和靈活性,具有很強(qiáng)的錯(cuò)誤處理能力,能夠同非關(guān)系數(shù)據(jù)源進(jìn)行通信。
ADO最主要的優(yōu)點(diǎn)在于易于使用、速度快、內(nèi)存支出少和磁盤遺跡小。
ADO.NET 是利用數(shù)據(jù)集的概念將數(shù)據(jù)庫數(shù)據(jù)讀入內(nèi)存中,然后在內(nèi)存中對(duì)數(shù)據(jù)進(jìn)行操作,最后將數(shù)據(jù)集數(shù)據(jù)回寫到源數(shù)據(jù)庫中。
OTL 是 Oracle, Odbc and DB2-CLI Template Library 的縮寫,是一個(gè)C++編譯中操控關(guān)系數(shù)據(jù)庫的模板庫,OTL中直接操作Oracle主要是通過Oracle提供的OCI接口進(jìn)行,進(jìn)行操作DB2數(shù)據(jù)庫則是通過CLI接口來進(jìn)行,至于MS的數(shù)據(jù)庫和其它一些數(shù)據(jù)庫,則OTL只提供了ODBC來操作的方式。當(dāng)然Oracle和DB2也可以由OTL間接使用ODBC的方式來進(jìn)行操縱。具有以下優(yōu)點(diǎn):跨平臺(tái);運(yùn)行效率高,與C語言直接調(diào)用API相當(dāng);開發(fā)效率高,起碼比ADO.net使用起來更簡單,更簡潔;部署容易,不需要ADO組件,不需要.net framework 等。
2、VC數(shù)據(jù)庫編程幾種方法
VC數(shù)據(jù)庫編程幾種方法,包括ODBC連接、MFC
ODBC連接、DAO連接、OLE
DB、OLE
DB
Templates連接、ADO、Oracle專用方法(OCI(Oracle
Call
Interface)訪問、Oracle
Object
OLE
C++
Class
Library)。
<1.>通用方法
1.ODBC連接
ODBC(Open
DataBase
Connectivity)是MSOA的一部分,是一個(gè)標(biāo)準(zhǔn)數(shù)據(jù)庫接口。它提供對(duì)關(guān)系數(shù)據(jù)庫訪問的統(tǒng)一接口,實(shí)現(xiàn)對(duì)異構(gòu)數(shù)據(jù)源的一致訪問。ODBC數(shù)據(jù)訪問由以下部分組成:
<1>句柄(Handles):ODBC使用句柄來標(biāo)識(shí)ODBC環(huán)境、連接、語句和描述器.<2>緩存區(qū)(Buffers):
<3>數(shù)據(jù)類型(Data
types)
<4>一致性級(jí)別(Conformance
levels)
用ODBC設(shè)計(jì)客戶端的一般步驟:
<1>分配ODBC環(huán)境
<2>分配連接句柄
<3>連接數(shù)據(jù)源
<4>構(gòu)造和執(zhí)行SQL語句
<5>獲得查詢結(jié)果
<6>斷開數(shù)據(jù)源的連接
<7>釋放ODBC環(huán)境
ODBC
API是一種適合數(shù)據(jù)庫底層開發(fā)的編程方法,ODBC
API提供大量對(duì)數(shù)據(jù)源的操作,ODBC
API能夠靈活地操作游標(biāo),支持各種幫定選項(xiàng),在所有ODBC相關(guān)編程中,API編程具有最高的執(zhí)行速度.因此,ODBC
API編程屬于底層編程。
2.MFC
ODBC連接
MFC
ODBC是MFC對(duì)ODBC進(jìn)行的封裝,以簡化對(duì)ODBC
API的 調(diào)用,從而實(shí)現(xiàn)面向?qū)ο蟮臄?shù)據(jù)庫編程接口.MFC
ODBC的封裝主要開發(fā)了CDatabase類和CRecordSet類
(1)CDatabase類
CDatabase類用于應(yīng)用程序建立同數(shù)據(jù)源的連接。CDatabase類中包含一個(gè)m_hdbc變量,它代表了數(shù)據(jù)源的連接句柄。如果要建立CDatabase類的實(shí)例,應(yīng)先調(diào)用該類的構(gòu)造函數(shù),再調(diào)用Open函數(shù),通過調(diào)用,初始化環(huán)境變量,并執(zhí)行與數(shù)據(jù)源的連接。在通過Close函數(shù)關(guān)閉數(shù)據(jù)源。
CDatabase類提供了對(duì)數(shù)據(jù)庫進(jìn)行操作的函數(shù)及事務(wù)操作。
(2)CRecordSet類
CRecordSet類定義了從數(shù)據(jù)庫接收或者發(fā)送數(shù)據(jù)到數(shù)據(jù)庫的成員變量,以實(shí)現(xiàn)對(duì)數(shù)據(jù)集的數(shù)據(jù)操作。
CRecordSet類的成員變量m_hstmt代表了定義該記錄集的SQL語句句柄,m_nFields為記錄集中字段的個(gè)數(shù),m_nParams為記錄集所使用的參數(shù)個(gè)數(shù)。
CRecordSet的記錄集通過CDatabase實(shí)例的指針實(shí)現(xiàn)同數(shù)據(jù)源的連接,即CRecordSet的成員變量m_pDatabase.MFC
ODBC編程更適合于界面型數(shù)據(jù)庫應(yīng)用程序的開發(fā),但由于CDatabase類和CRecordSet類提供的數(shù)據(jù)庫操作函數(shù)有限,支持的游標(biāo)類型也有限,限制了高效的數(shù)據(jù)庫開發(fā)。在編程層次上屬于高級(jí)編程。
應(yīng)用實(shí)例: 1.打開數(shù)據(jù)庫
CDatabase database;
database.OpenEx(_T(“DSN=zhuxue”),CDatabase::noOdbcDialog);//zhuxue為數(shù)據(jù)源名稱
2.關(guān)聯(lián)記錄集
CRecordset recset(&database);
3.查詢記錄
CString sSql1=“";
sSql1 = ”SELECT * FROM tablename“;
recset.Open(CRecordset::forwardOnly, sSql1, CRecordset::readOnly);
int ti=0;
CDBVariant var;//var可以轉(zhuǎn)換為其他類型的值
while(!recset.IsEOF())
{
//讀取Excel內(nèi)部數(shù)值
recset.GetFieldValue(”id“,var);
jiangxiang[ti].id=var.m_iVal;
recset.GetFieldValue(”name“, jiangxiang[ti].name);
ti++;
recset.MoveNext();
}
recset.Close();//關(guān)閉記錄集
4.執(zhí)行sql語句
CString sSql=”“;
sSql+=”delete * from 院系審核“;//清空表
database.ExecuteSQL(sSql);
sSql也可以為Insert ,Update等語句
5.讀取字段名
sSql = ”SELECT * FROM Sheet1“;
//讀取的文件有Sheet1表的定義,或?yàn)楸境绦蛏傻谋?// 執(zhí)行查詢語句
recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
int excelColCount=recset.GetODBCFieldCount();//列數(shù)
CString excelfield[30];
//得到記錄集的字段集合中的字段的總個(gè)數(shù)
for(i=0;i { CODBCFieldInfo fieldinfo; recset.GetODBCFieldInfo(i,fieldinfo); excelfield[i].name =fieldinfo.m_strName;//字段名 } 6.打開excel文件 CString sDriver = ”MICROSOFT EXCEL DRIVER(*.XLS)“;// Excel安裝驅(qū)動(dòng) CString sSql,sExcelFile;//sExcelFile為excel的文件路徑 TRY { // 創(chuàng)建進(jìn)行存取的字符串 sSql.Format(”DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=/“%s/”;DBQ=%s“,sDriver, sExcelFile, sExcelFile); // 創(chuàng)建數(shù)據(jù)庫(既Excel表格文件) if(database.OpenEx(sSql,CDatabase::noOdbcDialog)) { //可以把excel作為一個(gè)數(shù)據(jù)庫操作 } } catch(e) { TRACE1(”Excel驅(qū)動(dòng)沒有安裝: %s“,sDriver); AfxMessageBox(”讀取失敗,請(qǐng)檢查是否定義數(shù)據(jù)區(qū)Sheet1“); } 3.DAO連接 DAO(Data Access Object)是一組Microsoft Access/Jet數(shù)據(jù)庫引擎的COM自動(dòng)化接口.DAO直接與Access/Jet數(shù)據(jù)庫通信.通過Jet數(shù)據(jù)庫引擎,DAO也可以同其他數(shù)據(jù)庫進(jìn)行通信。DAO還封裝了Access數(shù)據(jù)庫的結(jié)構(gòu)單元,通過DAO可以直接修改Access數(shù)據(jù)庫的結(jié)構(gòu),而不必使用SQL的數(shù)據(jù)定義語言(DDL)。 DAO的體系結(jié)構(gòu)如下: DAO封裝的類: (1)CdaoWorkspace:對(duì)DAO工作區(qū)(數(shù)據(jù)庫處理事務(wù)管理器)的封裝 (2)CdaoDatabase:對(duì)DAO數(shù)據(jù)庫對(duì)象的封裝,負(fù)責(zé)數(shù)據(jù)庫連接.(3)CdaoRecordset:對(duì)DAO記錄集對(duì)象的封裝,代表所選的一組記錄.(4)CdaoTableDef:對(duì)表定義對(duì)象的封裝,代表基本表或附加表定義.(5)CdaoQueryDef:對(duì)查詢對(duì)象的封裝,包含所有查詢的定義.(6)CdaoException:DAO用于接收數(shù)據(jù)庫操作異常的類.(7)CDaoFieldExchange DAO提供了很好的數(shù)據(jù)庫編程的對(duì)象模型.但是,對(duì)數(shù)據(jù)庫的所有調(diào)用以及輸出的數(shù)據(jù)都必須通過Access/Jet數(shù)據(jù)庫引擎,這對(duì)于使用數(shù)據(jù)庫應(yīng)用程序,是嚴(yán)重的瓶頸。 DAO相對(duì)于ODBC來說,屬于高層的數(shù)據(jù)庫接口.4.OLE DB連接 OLE DB對(duì)ODBC進(jìn)行了兩方面的擴(kuò)展:一是提供了數(shù)據(jù)庫編程的OLE接口即COM,二是提供了一個(gè)可用于關(guān)系型和非關(guān)系型數(shù)據(jù)源的接口。 OLE DB提供了COM接口,與傳統(tǒng)的數(shù)據(jù)庫接口相比,有更好的健壯性和靈活性,具有很強(qiáng)的錯(cuò)誤處理能力,能夠同非關(guān)系數(shù)據(jù)源進(jìn)行通信。 與ODBC API一樣,OLE DB也屬于底層的數(shù)據(jù)庫編程接口,OLE DB結(jié)合了ODBC對(duì)關(guān)系數(shù)據(jù)庫的操作功能,并進(jìn)行擴(kuò)展,可以訪問非關(guān)系數(shù)據(jù)庫。 OLE DB訪問數(shù)據(jù)庫的原理如下: OLE DB程序結(jié)構(gòu): OLE DB由客戶(Consumer)和服務(wù)器(Provider)。客戶是使用數(shù)據(jù)的應(yīng)用程序,它通過OLE DB接口對(duì)數(shù)據(jù)提供者的數(shù)據(jù)進(jìn)行訪問和控制。OLE DB服務(wù)器是提供OLE DB接口的軟件組件。根據(jù)提供的內(nèi)容可以分為數(shù)據(jù)提供程序(Data Provider)和服務(wù)提供程序(Service Provider)。 程序結(jié)構(gòu)原理圖如下: <1>數(shù)據(jù)提供程序 數(shù)據(jù)提供程序擁有自己的數(shù)據(jù)并把數(shù)據(jù)以表格的形式呈現(xiàn)給使用者使用.<2>服務(wù)提供程序 服務(wù)提供程序是數(shù)據(jù)提供程序和使用者的結(jié)合。它是OLE DB體系結(jié)構(gòu)中的中間件,它是OLE DB數(shù)據(jù)源的使用者和數(shù)據(jù)使用程序的提供者 <3>數(shù)據(jù)使用程序 數(shù)據(jù)使用程序?qū)Υ鎯?chǔ)在數(shù)據(jù)提供程序中的數(shù)據(jù)進(jìn)行使用和控制.OLE DB開發(fā)程序的一般步驟: <1>初始化COM環(huán)境 <2>連接數(shù)據(jù)源 <3>打開對(duì)話 <4>執(zhí)行命令 <5>處理結(jié)果 <6>清除對(duì)象 應(yīng)用實(shí)例: 使用OLEDB編寫數(shù)據(jù)庫應(yīng)用程序 1 概述 OLE DB的存在為用戶提供了一種統(tǒng)一的方法來訪問所有不同種類的數(shù)據(jù)源。OLE DB可以在不同的數(shù)據(jù)源中進(jìn)行轉(zhuǎn)換。利用OLE DB,客戶端的開發(fā)人員在進(jìn)行數(shù)據(jù)訪問時(shí)只需把精力集中在很少的一些細(xì)節(jié)上,而不必弄懂大量不同數(shù)據(jù)庫的訪問協(xié)議。OLE DB是一套通過COM接口訪問數(shù)據(jù)的ActiveX接口。這個(gè)OLE DB接口相當(dāng)通用,足以提供一種訪問數(shù)據(jù)的統(tǒng)一手段,而不管存儲(chǔ)數(shù)據(jù)所使用的方法如何。同時(shí),OLE DB還允許開發(fā)人員繼續(xù)利用基礎(chǔ)數(shù)據(jù)庫技術(shù)的優(yōu)點(diǎn),而不必為了利用這些優(yōu)點(diǎn)而把數(shù)據(jù)移出來。 使用ATL使用OLE DB數(shù)據(jù)使用程序 由于直接使用OLE DB的對(duì)象和接口設(shè)計(jì)數(shù)據(jù)庫應(yīng)用程序需要書寫大量的代碼。為了簡化程序設(shè)計(jì),Visual C++提供了ATL模板用于設(shè)計(jì)OLE DB數(shù)據(jù)應(yīng)用程序和數(shù)據(jù)提供程序。利用ATL模板可以很容易地將OLE DB與MFC結(jié)合起來,使數(shù)據(jù)庫的參數(shù)查詢等復(fù)雜的編程得到簡化。MFC提供的數(shù)據(jù)庫類使OLE DB的編程更具有面向?qū)ο蟮奶匦浴iual C++所提供用于OLE DB的ATL模板可分為數(shù)據(jù)提供程序的模板和數(shù)據(jù)使用程序的模板。 使用ATL模板創(chuàng)建數(shù)據(jù)應(yīng)用程序一般有以下幾步驟: 1)、創(chuàng)建應(yīng)用框架 2)、加入ATL產(chǎn)生的模板類 3)、在應(yīng)用中使用產(chǎn)生的數(shù)據(jù)訪問對(duì)象3 不用ATL使用OLE DB數(shù)據(jù)使用程序 利用ATL模板產(chǎn)生數(shù)據(jù)使用程序較為簡單,但適用性不廣,不能動(dòng)態(tài)適應(yīng)數(shù)據(jù)庫的變化。下面我們介紹直接使用MFC OLE DB類來生成數(shù)據(jù)使用程序。模板的使用 OLE DB數(shù)據(jù)使用者模板是由一些模板組成的,包括如下一些模板,下面對(duì)一些常用類作一些介紹。1)、會(huì)話類 CDataSource類 CDataSource類與OLE DB的數(shù)據(jù)源對(duì)象相對(duì)應(yīng)。這個(gè)類代表了OLE DB數(shù)據(jù)提供程序和數(shù)據(jù)源之間的連接。只有當(dāng)數(shù)據(jù)源的連接被建立之后,才能產(chǎn)生會(huì)話對(duì)象,可以調(diào)用Open來打開數(shù)據(jù)源的連接。CSession類 CSession所創(chuàng)建的對(duì)象代表了一個(gè)單獨(dú)的數(shù)據(jù)庫訪問的會(huì)話。一個(gè)用CDataSource類產(chǎn)生的數(shù)據(jù)源對(duì)象可以創(chuàng)建一個(gè)或者多個(gè)會(huì)話,要在數(shù)據(jù)源對(duì)象上產(chǎn)生一個(gè)會(huì)話對(duì)象,需要調(diào)用函數(shù)Open()來打開。同時(shí),會(huì)話對(duì)象還可用于創(chuàng)建事務(wù)操作。 CEnumeratorAccessor類 CEnumeratorAccessor類是用來訪問枚舉器查詢后所產(chǎn)生的行集中可用數(shù)據(jù)提供程序的信息的訪問器,可提供當(dāng)前可用的數(shù)據(jù)提供程序和可見的訪問器。2)、訪問器類 CAcessor類 CAccessor類代表與訪問器的類型。當(dāng)用戶知道數(shù)據(jù)庫的類型和結(jié)構(gòu)時(shí),可以使用此類。它支持對(duì)一個(gè)行集采用多個(gè)訪問器,并且,存放數(shù)據(jù)的緩沖區(qū)是由用戶分配的。CDynamicAccessor類 CDynamicAccessor類用來在程序運(yùn)行時(shí)動(dòng)態(tài)的創(chuàng)建訪問器。當(dāng)系統(tǒng)運(yùn)行時(shí),可以動(dòng)態(tài)地從行集中獲得列的信息,可根據(jù)此信息動(dòng)態(tài)地創(chuàng)建訪問器。CManualAccessor類 CManualAccessor類中以在程序運(yùn)行時(shí)將列與變量綁定或者是將參數(shù)與變量捆定。3)、行集類 CRowSet類 CRowSet類封裝了行集對(duì)象和相應(yīng)的接口,并且提供了一些方法用于查詢、設(shè)置數(shù)據(jù)等。可以用Move()等函數(shù)進(jìn)行記錄移動(dòng),用GetData()函數(shù)讀取數(shù)據(jù),用Insert()、Delete()、SetData()來更新數(shù)據(jù)。CBulkRowset類 CBulkRowset類用于在一次調(diào)用中取回多個(gè)行句柄或者對(duì)多個(gè)行進(jìn)行操作。CArrayRowset類 CArrayRowset類提供用數(shù)組下標(biāo)進(jìn)行數(shù)據(jù)訪問。4)、命令類 CTable類 CTable類用于對(duì)數(shù)據(jù)庫的簡單訪問,用數(shù)據(jù)源的名稱得到行集,從而得到數(shù)據(jù)。CCommand類 CCommand類用于支持命令的數(shù)據(jù)源。可以用Open()函數(shù)來執(zhí)行SQL命令,也可以Prepare()函數(shù)先對(duì)命令進(jìn)行準(zhǔn)備,對(duì)于支持命令的數(shù)據(jù)源,可以提高程序的靈活性和健壯性。 在stdafx.h頭文件里,加入如下代碼。#include 在打開數(shù)據(jù)源,會(huì)話,行集對(duì)象后就可以獲取數(shù)據(jù)了。所獲取的數(shù)據(jù)類型取決于所用的存取程序,可能需要綁定列。按以下步驟。 1、用正確的命令打開行集對(duì)象。 2、如果使用CManualAccessor,在使用之前與相應(yīng)列進(jìn)行綁定。要綁定列,可以用函數(shù)GetColumnInfo,如下所示: // Get the column information ULONG ulColumns = 0;DBCOLUMNINFO* pColumnInfo = NULL;LPOLESTR pStrings = NULL;if(rs.GetColumnInfo(&ulColumns, &pColumnInfo, &pStrings)!= S_OK)AfxThrowOLEDBException(rs.m_pRowset, IID_IColumnsInfo);struct MYBIND* pBind = new MYBIND[ulColumns];rs.CreateAccessor(ulColumns, &pBind[0], sizeof(MYBIND)*ulColumns);for(ULONG l=0;l 3、用while循環(huán)來取數(shù)據(jù)。在循環(huán)中,調(diào)用MoveNext來測(cè)試光標(biāo)的返回值是否為S_OK,如下所示: while(rs.MoveNext()== S_OK){ // Add code to fetch data here // If you are not using an auto accessor, call rs.GetData()} 4、在while循環(huán)內(nèi),可以通過不同的存取程序獲取數(shù)據(jù)。1)如果使用的是CAccessor類,可以通過使用它們的數(shù)據(jù)成員進(jìn)行直接訪問。如下所示: 2)如果使用的是CDynamicAccessor 或CDynamicParameterAccessor 類,可以通過GetValue或GetColumn函數(shù)來獲取數(shù)據(jù)。可以用GetType來獲取所用數(shù)據(jù)類型。如下所示: while(rs.MoveNext()== S_OK){ // Use the dynamic accessor functions to retrieve your // data ULONG ulColumns = rs.GetColumnCount(); for(ULONG i=0;i { rs.GetValue(i); } } 3)如果使用的是CManualAccessor,可以指定自己的數(shù)據(jù)成員,綁定它們。就可以直接存取。如下所示: while(rs.MoveNext()== S_OK){ // Use the data members you specified in the calls to // AddBindEntry.wsprintf(”%s“, szFoo);} 決定行集的數(shù)據(jù)類型 在運(yùn)行時(shí)決定數(shù)據(jù)類型,要用動(dòng)態(tài)或手工的存取程序。如果用的是手工存取程序,可以用GetColumnInfo函數(shù)得到行集的列信息。從這里可以得到數(shù)據(jù)類型。4 總結(jié) 由于現(xiàn)在有多種數(shù)據(jù)源,想要對(duì)這些數(shù)據(jù)進(jìn)行訪問管理的唯一途徑就是通過一些同類機(jī)制來實(shí)現(xiàn),如OLE DB。高級(jí)OLE DB結(jié)構(gòu)分成兩部分:客戶和提供者。客戶使用由提供者生成的數(shù)據(jù)。 就像其它基于COM的多數(shù)結(jié)構(gòu)一樣,OLE DB的開發(fā)人員需要實(shí)現(xiàn)很多的接口,其中大部分是模板文件。 當(dāng)生成一個(gè)客戶對(duì)象時(shí),可以通過ATL對(duì)象向?qū)е赶蛞粋€(gè)數(shù)據(jù)源而創(chuàng)建一個(gè)簡單的客戶。ATL對(duì)象向?qū)?huì)檢查數(shù)據(jù)源并創(chuàng)建數(shù)據(jù)庫的客戶端代理。從那里,可以通過OLE DB客戶模板使用標(biāo)準(zhǔn)的瀏覽函數(shù)。 當(dāng)生成一個(gè)提供者時(shí),向?qū)峁┝艘粋€(gè)很好的開端,它們僅僅是生成了一個(gè)簡單的提供者來列舉某一目錄下的文件。然后,提供者模板包含了OLE DB支持的完全補(bǔ)充內(nèi)容。在這種支持下,用戶可以創(chuàng)建OLE DB提供者,來實(shí)現(xiàn)行集定位策略、數(shù)據(jù)的讀寫以及建立書簽。應(yīng)用案例: Visual C++中使用OLE DB讀寫SQL Server 在需要對(duì)數(shù)據(jù)庫進(jìn)行操作時(shí),OLE DB總是被認(rèn)為是一種效率最高但最難的方法。但是以我最近使用OLE DB的經(jīng)驗(yàn)看來,OLE DB的效率高則高矣,但卻一點(diǎn)都不難。說它難恐怕主要是因?yàn)榭蓞⒖嫉闹形馁Y料太少,為了幫助以后需要接觸OLE DB的同行,我撰寫了這篇文章。本文包含如下內(nèi)容: 1.OLE DB寫數(shù)據(jù)庫; 2.OLE DB讀數(shù)據(jù)庫; 3.OLE DB對(duì)二進(jìn)制數(shù)據(jù)(text、ntext、image等)的處理。 首先來看看對(duì)SQL Server進(jìn)行寫操作的代碼,有一定VC基礎(chǔ)的讀者應(yīng)該可以很順利地看懂。OLE DB寫數(shù)據(jù)庫,就是這么簡單! 注: 1.以下代碼中使用的模板類EAutoReleasePtr 2.以下代碼均在UNICODE環(huán)境下編譯,因?yàn)閳?zhí)行的SQL語句必須是UNICODE的。設(shè)置工程為UNICODE的方法是:首先在project->settings->C/C++的屬性頁中的Preprocessor中,刪除_MBCS寫入U(xiǎn)NICODE,_UNICODE。然后在link屬性頁中Category中選擇output,在Entry-Point symbol 中添加wWinMainCRTStartup。 EAutoReleasePtr //失敗,可能是因?yàn)閿?shù)據(jù)庫沒有啟動(dòng)、用戶名密碼錯(cuò)等等 return;}EAutoReleasePtr //出錯(cuò) return;}EAutoReleasePtr //出錯(cuò) return;}hResult = ExecuteSQL(pICommand, pICommandText, _T(”USE PBDATA“));if(FAILED(hResult)){ //如果這里失敗,那就是SQL語句執(zhí)行失敗。在此處,就是PBDATA還未創(chuàng)建 return;} // 創(chuàng)建表 ExecuteSQL(pICommand, pICommandText, _T(”CREATE TABLE 2005_1(Volume real NOT NULL,ID int NOT NULL IDENTITY)“)); // 添加記錄 ExecuteSQL(pICommand, pICommandText, _T(”INSERT INTO 2005_1 VALUES(100.0)“));//...其中幾個(gè)函數(shù)的代碼如下: HRESULT ConnectDatabase(IDBInitialize** ppIDBInitialize, LPCTSTR pszDataSource, LPCTSTR pszUserID, LPCTSTR pszPassword){ ASSERT(ppIDBInitialize!= NULL && pszDataSource!= NULL && pszUserID!= NULL && pszPassword!= NULL); UINT uTimeout = 15U;// 連接數(shù)據(jù)庫超時(shí)(秒) TCHAR szInitStr[1024]; VERIFY(1023 >= wsprintf(szInitStr, _T(”Provider=SQLOLEDB;Data Source=%s;Initial Catalog=master;User Id=%s;Password=%s;Connect Timeout=%u“), pszDataSource, pszUserID, pszPassword, uTimeout)); //Initial Catalog=master指明連接成功后,”USE master“。 EAutoReleasePtr HRESULT hResult = ::CoCreateInstance(CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER,IID_IDataInitialize,(void**)&pIDataInitialize); if(FAILED(hResult)) { return hResult; } EAutoReleasePtr hResult = pIDataInitialize->GetDataSource(NULL, CLSCTX_INPROC_SERVER,(LPCOLESTR)szInitStr,IID_IDBInitialize,(IUnknown**)&pIDBInitialize); if(FAILED(hResult)) { return hResult; } hResult = pIDBInitialize->Initialize(); if(FAILED(hResult)) { return hResult; } * ppIDBInitialize = pIDBInitialize.Detach(); return S_OK;} HRESULT CreateSession(IDBInitialize* pIDBInitialize, IOpenRowset** ppIOpenRowset){ ASSERT(pIDBInitialize!= NULL && ppIOpenRowset!= NULL); EAutoReleasePtr HRESULT hResult = pIDBInitialize->QueryInterface(IID_IDBCreateSession,(void**)&pSession); if(FAILED(hResult)) { return hResult; } EAutoReleasePtr hResult = pSession->CreateSession(NULL, IID_IOpenRowset,(IUnknown**)&pIOpenRowset); if(FAILED(hResult)) { return hResult; } * ppIOpenRowset = pIOpenRowset.Detach(); return S_OK;} HRESULT CreateCommand(IOpenRowset* pIOpenRowset, ICommand** ppICommand, ICommandText** ppICommandText){ ASSERT(pIOpenRowset!= NULL && ppICommand!= NULL && ppICommandText!= NULL); HRESULT hResult; EAutoReleasePtr { EAutoReleasePtr hResult = pIOpenRowset->QueryInterface(IID_IDBCreateCommand,(void**)&pICreateCommand); if(FAILED(hResult)) { return hResult; } hResult = pICreateCommand->CreateCommand(NULL, IID_ICommand,(IUnknown**)&pICommand); if(FAILED(hResult)) { return hResult; } } EAutoReleasePtr hResult = pICommand->QueryInterface(&pICommandText); if(FAILED(hResult)) { return hResult; } * ppICommand = pICommand.Detach(); * ppICommandText = pICommandText.Detach(); return S_OK;} HRESULT ExecuteSQL(ICommand* pICommand, ICommandText* pICommandText, LPCTSTR pszCommand, LONG* plRowsAffected){ ASSERT(pICommand!= NULL && pICommandText!= NULL && pszCommand!= NULL && pszCommand[0]!= 0); HRESULT hResult = pICommandText->SetCommandText(DBGUID_DBSQL,(LPCOLESTR)pszCommand); if(FAILED(hResult)) { return hResult; } LONG lAffected; hResult = pICommand->Execute(NULL, IID_NULL, NULL, plRowsAffected == NULL ? &lAffected : plRowsAffected,(IUnknown**)NULL); return hResult;} 以上就是寫數(shù)據(jù)庫的全部代碼了,是不是很簡單呢?下面再來讀的。 // 先用與上面代碼中一樣的步驟獲取pICommand,pICommandText。此處省略 HRESULT hResult = pICommandText->SetCommandText(DBGUID_DBSQL,(LPCOLESTR)_T(”SELECT Volume FROM 2005_1 WHERE ID = @@IDENTITY"));//取我們剛剛添加的那一條記錄 if(FAILED(hResult)){ return;} LONG lAffected;EAutoReleasePtr return;} EAutoReleasePtr return;} // 一個(gè)根據(jù)表中各字段的數(shù)值類型而定義的結(jié)構(gòu),用于存儲(chǔ)返回的各字段的值 struct CLoadLastFromDB { DBSTATUS dwdsVolume; DWORD dwLenVolume; float fVolume;}; // 此處我們只查詢了一個(gè)字段。如果要查詢多個(gè)字段,CLoadLastFromDB中要添加相應(yīng)的字段定義,下面的dbBinding也要相應(yīng)擴(kuò)充。dbBinding[].iOrdinal要分別指向各個(gè)字段,dbBinding[].wType要根據(jù)字段類型賦合適的值。 DBBINDING dbBinding[1];dbBinding[0].iOrdinal = 1; // Volume 字段的位置,從 1 開始 dbBinding[0].obValue = offsetof(CLoadLastFromDB, fVolume);dbBinding[0].obLength = offsetof(CLoadLastFromDB, dwLenVolume);dbBinding[0].obStatus = offsetof(CLoadLastFromDB, dwdsVolume);dbBinding[0].pTypeInfo = NULL;dbBinding[0].pObject = NULL;dbBinding[0].pBindExt = NULL;dbBinding[0].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;dbBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;dbBinding[0].eParamIO = DBPARAMIO_NOTPARAM;dbBinding[0].cbMaxLen = 0;dbBinding[0].dwFlags = 0;