怎么用asp創(chuàng)建sql數(shù)據(jù)表相關(guān)操作_第1頁(yè)
怎么用asp創(chuàng)建sql數(shù)據(jù)表相關(guān)操作_第2頁(yè)
怎么用asp創(chuàng)建sql數(shù)據(jù)表相關(guān)操作_第3頁(yè)
怎么用asp創(chuàng)建sql數(shù)據(jù)表相關(guān)操作_第4頁(yè)
怎么用asp創(chuàng)建sql數(shù)據(jù)表相關(guān)操作_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論