版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、-. z下面是利用sql語(yǔ)句創(chuàng)立數(shù)據(jù)庫(kù)、表、存儲(chǔ)過(guò)程、視圖、索引、規(guī)則、修改表、查看數(shù)據(jù)等的方法。所要增加的控件如下:imports system.dataimports system.data.sqlclientpublic class form1 inherits system.windows.forms.form private connectionstring as string = data source=.;initial catalog=;user id=sa;password=; private reader as sqldatareader = nothing private
2、 conn as sqlconnection = nothing private cmd as sqlmand = nothing private altertablebtn as system.windows.forms.button private sql as string = nothing private createothersbtn as system.windows.forms.button*region windows 窗體設(shè)計(jì)器生成的代碼 窗體重寫處置以清理組件列表。 protected overloads overrides sub dispose(byval dispo
3、sing as boolean) if disposing then if not (ponents is nothing) then ponents.dispose() end if end if mybase.dispose(disposing) end sub public sub new() mybase.new() initializeponent() end sub private ponents as system.ponentmodel.icontainer friend withevents datagrid1 as system.windows.forms.datagrid
4、 friend withevents createdbbtn as system.windows.forms.button friend withevents createtablebtn as system.windows.forms.button friend withevents createspbtn as system.windows.forms.button friend withevents createviewbtn as system.windows.forms.button friend withevents btnaltertable as system.windows.
5、forms.button friend withevents btncreateothers as system.windows.forms.button friend withevents btndroptable as system.windows.forms.button friend withevents btnviewdata as system.windows.forms.button friend withevents btnviewsp as system.windows.forms.button friend withevents btnviewview as system.
6、windows.forms.button private sub initializeponent() me.createdbbtn = new system.windows.forms.button() me.createtablebtn = new system.windows.forms.button() me.createspbtn = new system.windows.forms.button() me.createviewbtn = new system.windows.forms.button() me.btnaltertable = new system.windows.f
7、orms.button() me.btncreateothers = new system.windows.forms.button() me.btndroptable = new system.windows.forms.button() me.btnviewdata = new system.windows.forms.button() me.btnviewsp = new system.windows.forms.button() me.btnviewview = new system.windows.forms.button() me.datagrid1 = new system.wi
8、ndows.forms.datagrid() ctype(me.datagrid1, system.ponentmodel.isupportinitialize).begininit() me.suspendlayout() createdbbtn me.createdbbtn.location = new system.drawing.point(19, 9) = createdbbtn me.createdbbtn.size = new system.drawing.size(104, 23) me.createdbbtn.tabinde* = 0
9、me.createdbbtn.te*t = 創(chuàng)立數(shù)據(jù)庫(kù) createtablebtn me.createtablebtn.location = new system.drawing.point(139, 9) = createtablebtn me.createtablebtn.tabinde* = 1 me.createtablebtn.te*t = 創(chuàng)立表 createspbtn me.createspbtn.location = new system.drawing.point(230, 9) = cr
10、eatespbtn me.createspbtn.size = new system.drawing.size(104, 23) me.createspbtn.tabinde* = 2 me.createspbtn.te*t = 創(chuàng)立存儲(chǔ)過(guò)程 createviewbtn me.createviewbtn.location = new system.drawing.point(350, 9) = createviewbtn me.createviewbtn.tabinde* = 3 me.createviewbtn.te*t = 創(chuàng)立視圖 btnalt
11、ertable me.btnaltertable.location = new system.drawing.point(441, 9) = btnaltertable me.btnaltertable.tabinde* = 4 me.btnaltertable.te*t = 修改表 btncreateothers me.btncreateothers.location = new system.drawing.point(17, 43) = btncreateothers me.btncreateot
12、hers.size = new system.drawing.size(104, 23) me.btncreateothers.tabinde* = 5 me.btncreateothers.te*t = 創(chuàng)立規(guī)則和索引 btndroptable me.btndroptable.location = new system.drawing.point(138, 43) = btndroptable me.btndroptable.tabinde* = 6 me.btndroptable.te*t = 刪除表 btnviewdata me.btnviewd
13、ata.location = new system.drawing.point(351, 43) = btnviewdata me.btnviewdata.tabinde* = 7 me.btnviewdata.te*t = 查看數(shù)據(jù) btnviewsp me.btnviewsp.location = new system.drawing.point(230, 43) = btnviewsp me.btnviewsp.size = new system.drawing.size(104, 23) me.btnviews
14、p.tabinde* = 8 me.btnviewsp.te*t = 查看存儲(chǔ)過(guò)程 btnviewview me.btnviewview.location = new system.drawing.point(443, 43) = btnviewview me.btnviewview.tabinde* = 9 me.btnviewview.te*t = 查看視圖 datagrid1 me.datagrid1.datamember = me.datagrid1.headerforecolor = system.drawing.systemcolors.co
15、ntrolte*t me.datagrid1.location = new system.drawing.point(20, 76) = datagrid1 me.datagrid1.size = new system.drawing.size(500, 183) me.datagrid1.tabinde* = 10 form1 me.autoscalebasesize = new system.drawing.size(5, 13) me.clientsize = new system.drawing.size(538, 281) me.controls.
16、addrange(new system.windows.forms.control() me.datagrid1, me.btnviewview, _ me.btnviewsp, me.btnviewdata, me.btndroptable, me.btncreateothers, me.btnaltertable, _ me.createviewbtn, me.createspbtn, me.createtablebtn, me.createdbbtn) = form1 me.te*t = 動(dòng)態(tài)創(chuàng)立sql server數(shù)據(jù)庫(kù)、表、存儲(chǔ)過(guò)程等架構(gòu)信息 ctype(me.dat
17、agrid1, system.ponentmodel.isupportinitialize).endinit() me.resumelayout(false) end sub*end region 創(chuàng)立數(shù)據(jù)庫(kù) private sub createdbbtn_click(byval sender as system.object, byval e as system.eventargs) _ handles createdbbtn.click conn = new sqlconnection(connectionstring) 翻開連接 if conn.state connectionstate
18、.open then conn.open() end if mydatabase為數(shù)據(jù)庫(kù)名稱 dim sql as string = create database mydatabase on primary (name=mydatabase_data, filename = + _ d:mydatabase.mdf, size=3, + ma*size=5, filegrowth=10%) log on + (name=mydatabase_log, + _ filename=d:mydatabase.ldf,size=3, + ma*size=20,filegrowth=1) cmd =
19、new sqlmand(sql, conn) try cmd.e*ecutenonquery() catch ae as sqle*ception messagebo*.show(ae.message.tostring() end try end sub 創(chuàng)立表 private sub createtablebtn_click(byval sender as system.object, byval e as system.eventargs) _ handles createtablebtn.click conn = new sqlconnection(connectionstring) 翻
20、開連接 if conn.state = connectionstate.open then conn.close() end if connectionstring = data source=.;initial catalog=mydatabase;user id=sa;password=; conn.connectionstring = connectionstring conn.open() sql = create table mytable + (myid integer constraint pkeymyid primary key, + _ myname char(50) not
21、 null, myaddress char(255), myvalues float) cmd = new sqlmand(sql, conn) try cmd.e*ecutenonquery() 添加紀(jì)錄 sql = insert into mytable(myid, myname, myaddress, myvalues) + _ values (1001, _【孟憲會(huì)之精彩世界】之一, * 100 ) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytable(myid, myname, mya
22、ddress, myvalues) + _ values (1002, 【孟憲會(huì)之精彩世界】之二, .erp800./net_lover/, 99) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytable(myid, myname, myaddress, myvalues) + _ values (1003, 【孟憲會(huì)之精彩世界】之三, * 99) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytabl
23、e(myid, myname, myaddress, myvalues) + _ values (1004, 【孟憲會(huì)之精彩世界】之四, .erp800./net_lover/, 100) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() catch ae as sqle*ception messagebo*.show(ae.message.tostring() end try end sub 創(chuàng)立存儲(chǔ)過(guò)程 private sub createspbtn_click(byval sender as system.object, byval e
24、 as system.eventargs) _ handles createspbtn.click sql = create procedure myproc as + select myname, myaddress from mytable go e*ecutesqlstmt(sql) end sub 創(chuàng)立視圖 private sub createviewbtn_click(byval sender as system.object, byval e as system.eventargs) _ handles createviewbtn.click sql = create view m
25、yview as select myname from mytable e*ecutesqlstmt(sql) end sub 修改表 private sub btnaltertable_click(byval sender as system.object, byval e as system.eventargs) _ handles btnaltertable.click sql = alter table mytable add newcol datetime not null default (getdate() e*ecutesqlstmt(sql) end sub 創(chuàng)立規(guī)則和索引
26、private sub btncreateothers_click(byval sender as system.object, byval e as system.eventargs) _ handles btncreateothers.click sql = create unique inde* + myid* on mytable(myname) e*ecutesqlstmt(sql) sql = create rule myrule + as myvalues = 90 and myvalues 9999 e*ecutesqlstmt(sql) end sub 刪除表 private
27、 sub btndroptable_click(byval sender as system.object, byval e as system.eventargs) _ handles btndroptable.click dim sql as string = drop table mytable e*ecutesqlstmt(sql) end sub 瀏覽表數(shù)據(jù) private sub btnviewdata_click(byval sender as system.object, byval e as system.eventargs) _ handles btnviewdata.cl
28、ick conn = new sqlconnection(connectionstring) if conn.state = connectionstate.open then conn.close() end if connectionstring = data source=.;initial catalog=mydatabase;user id=sa;password=; conn.connectionstring = connectionstring conn.open() dim da as new sqldataadapter(select * from mytable, conn
29、) dim ds as new dataset(mytable) da.fill(ds, mytable) datagrid1.datasource = ds.tables(mytable).defaultview end sub 瀏覽存儲(chǔ)過(guò)程 private sub btnviewsp_click(byval sender as system.object, byval e as system.eventargs) _ handles btnviewsp.click conn = new sqlconnection(connectionstring) if conn.state = connectionstate.open then conn.close() end if connectionstring = data source=.;initial catalog=mydatabase;user id=sa;password=; conn.connectionstring = connectionstring conn.open() dim da as new sqldataadapter(myproc, conn) dim ds as new dataset(sp) da.fill(ds, sp) da
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年度線上直播帶貨平臺(tái)合作框架協(xié)議范本3篇
- 高三級(jí)綜合練習(xí)高三語(yǔ)文
- 2024年智能電動(dòng)門供應(yīng)安裝協(xié)議版B版
- 2024年度市政道路擋土墻施工勞務(wù)分包協(xié)議3篇
- 對(duì)傲慢與偏見的讀后感
- 2024年度文化創(chuàng)意產(chǎn)業(yè)員工入股合作框架協(xié)議范本3篇
- 2024企業(yè)環(huán)保項(xiàng)目勞務(wù)輸出與污染治理合同范本3篇
- 數(shù)學(xué)組信息技術(shù)研修計(jì)劃范文(7篇)
- 我與公司共成長(zhǎng)演講稿8篇
- 幼兒閱讀心得
- 地球科學(xué)概論(長(zhǎng)安大學(xué))智慧樹知到期末考試答案2024年
- 期末(試題)-2023-2024學(xué)年劍橋少兒英語(yǔ)一級(jí)上冊(cè)
- 人教版三年級(jí)數(shù)學(xué)下冊(cè)除數(shù)是一位數(shù)的除法豎式計(jì)算500道題
- 2024年其他招錄考試-大學(xué)畢業(yè)生士兵提干筆試歷年真題薈萃含答案
- 總裁辦公室運(yùn)營(yíng)管理手冊(cè)
- 人流手術(shù)報(bào)告單
- 推進(jìn)新型工業(yè)化思考
- 培養(yǎng)學(xué)生深度思考的能力
- 醫(yī)院感染管理培訓(xùn)課件:內(nèi)鏡操作中的感染控制要點(diǎn)
- 美容皮膚科培訓(xùn)課件
- 《傳染病及預(yù)防》教學(xué)設(shè)計(jì)
評(píng)論
0/150
提交評(píng)論