版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、-. z下面是利用sql语句创立数据库、表、存储过程、视图、索引、规则、修改表、查看数据等的方法。所要增加的控件如下: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 窗体设计器生成的代码 窗体重写处置以清理组件列表。 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 = 创立数据库 createtablebtn me.createtablebtn.location = new system.drawing.point(139, 9) = createtablebtn me.createtablebtn.tabinde* = 1 me.createtablebtn.te*t = 创立表 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 = 创立存储过程 createviewbtn me.createviewbtn.location = new system.drawing.point(350, 9) = createviewbtn me.createviewbtn.tabinde* = 3 me.createviewbtn.te*t = 创立视图 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 = 创立规则和索引 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 = 查看数据 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 = 查看存储过程 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 = 动态创立sql server数据库、表、存储过程等架构信息 ctype(me.dat
17、agrid1, system.ponentmodel.isupportinitialize).endinit() me.resumelayout(false) end sub*end region 创立数据库 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为数据库名称 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 创立表 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() 添加纪录 sql = insert into mytable(myid, myname, myaddress, myvalues) + _ values (1001, _【孟宪会之精彩世界】之一, * 100 ) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytable(myid, myname, mya
22、ddress, myvalues) + _ values (1002, 【孟宪会之精彩世界】之二, .erp800./net_lover/, 99) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytable(myid, myname, myaddress, myvalues) + _ values (1003, 【孟宪会之精彩世界】之三, * 99) cmd = new sqlmand(sql, conn) cmd.e*ecutenonquery() sql = insert into mytabl
23、e(myid, myname, myaddress, myvalues) + _ values (1004, 【孟宪会之精彩世界】之四, .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 创立存储过程 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 创立视图 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 创立规则和索引
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 浏览表数据 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 浏览存储过程 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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四年级下学期班队工作计划
- 安全事故应对演练工作计划
- 个人工作总结范文
- 关于艺术工作计划范文
- 2024年1月七年级主任工作计划范文
- 销售行业工作计划范例
- 学校教师素质提升工程全员培训工作计划范文
- 销售月工作总结及下个月计划
- 班主任与教学工作计划锦集
- 2024年春季学校工作计划例文
- 《清明上河图》-完整版PPT
- 奇瑞汽车转向系统碰撞建模指南V
- 血管瘤的护理诊断及护理措施ppt
- 防孤岛测试报告
- 一种用滚轮装置进行桥架电缆敷设的方法
- 治理校园噪声五年级综合实践上册课件
- 高压旋喷桩对地基进行加固处理施工方案
- GWJ 009-2016 无线电管理频率数据库结构技术规范
- 应急处置与逃生自救互救知识培训
- CRM系统操作手册
- 儿科应急预案及程序
评论
0/150
提交评论