ADO连接数据库实验报告_第1页
ADO连接数据库实验报告_第2页
ADO连接数据库实验报告_第3页
ADO连接数据库实验报告_第4页
ADO连接数据库实验报告_第5页
已阅读5页,还剩1页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第七章任务一实验目的:学习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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论