版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第七章任务一实验目的:学习ASP.NET网页和SQLServer数据库建立连接实验要求:1.将ASP.NET网页和SQLServer数据库建立连接2.向学生数据库中的学生表中输入数据3.使用Response输出学生表中所有数据4.使用GridView控件输出学生表中的所有数据实验步骤:第一步:建立个数据库第二步:连接起来第三步:编写处理代码实验结果:详细代码:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){SqlConnectionSunCon=newSqlConnection("DataSource=djsw43;InitialCatalog=学生管理;IntegratedSecurity=True");SunCon.Open();stringStuSQL;StuSQL="INSERTINTO学生(学号,姓名,性别,籍贯,班级,电话)";StuSQL=StuSQL+"VALUES('"+TextBox1.Text+"','"+TextBox2.Text;StuSQL=StuSQL+"','"+TextBox3.Text+"','"+TextBox4.Text;StuSQL=StuSQL+"','"+TextBox5.Text+"','"+TextBox6.Text+"')";SqlCommandStuIns=newSqlCommand(StuSQL,SunCon);StuIns.ExecuteNonQuery();SunCon.Close();}protectedvoidButton2_Click(objectsender,EventArgse){Response.Redirect("sun7_1a.aspx");}protectedvoidButton3_Click(objectsender,EventArgse){Response.Redirect("sun7_1b.aspx");}}sun7_1a.aspx.cs代码:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclasssun7_1:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){SqlConnectionSunCon=newSqlConnection("DataSource=djsw43;InitialCatalog=学生管理;IntegratedSecurity=True");SunCon.Open();stringStuSQL;StuSQL="SELECT学号,姓名,性别,籍贯,班级,电话FROM学生";SqlCommandStuIns=newSqlCommand(StuSQL,SunCon);SqlDataReaderSunDa=StuIns.ExecuteReader();while(SunDa.Read()){Response.Write(SunDa.FieldCount);Response.Write(SunDa.GetString(0)+"");Response.Write(SunDa.GetString(1)+"");Response.Write(SunDa.GetString(2)+"");Response.Write("<br/>");}SunCon.Close();}}sun7_1b.aspx.页面中插入GridView按钮代码:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclasssun7_1b:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){SqlConnectionSunCon=newSqlConnection("DataSource=djsw43;InitialCatalog=学生管理;IntegratedSecurity=True");SunCon.Open();stringStuSQL;StuSQL="SELECT学号,姓名,性别,籍贯,班级,电话FROM学生";SqlCommandStuIns=newSqlComman
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年高速公路收费AI用户满意度提升策略
- 2026年AI临床诊断工程师持续教育体系构建
- 玻璃隔墙施工工艺及施工方法
- 历年计算机软考程序员笔试真题及答案
- 2026年中职(园林技术)阶段测试试题及答案
- 公路穿越安全检查措施培训课件
- 2026年中国儿童气质测试题及答案
- 2026年航天行测测试题及答案
- 2026小学教资气质类型教育启示课件
- 2026中学音乐戏剧教学方法课件
- 2026年安全生产月知识竞赛试题(7套完整版 含答案)
- 2026文化和旅游部恭王府博物馆招聘应届毕业生4人考试备考试题及答案解析
- 房地产项目资产收购协议
- 《中国hiv暴露前预防用药专家共识(版)》解读
- 绿化保洁物业工作总结
- 名誉权纠纷答辩状范本
- 工业机器人操作与编程课件
- 高中酸碱盐溶解度表(全)
- 2021年湖北省新高考物理试卷(附答案详解)
- 《广告媒体策划》
- 无人机组装调试与检修 第五章 无人机系统调试
评论
0/150
提交评论