C#实验四 数据库基本操作_第1页
C#实验四 数据库基本操作_第2页
C#实验四 数据库基本操作_第3页
C#实验四 数据库基本操作_第4页
C#实验四 数据库基本操作_第5页
已阅读5页,还剩6页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

C#实验四数据库基本操作C#实验四数据库基本操作C#实验四数据库基本操作xxx公司C#实验四数据库基本操作文件编号:文件日期:修订次数:第1.0次更改批准审核制定方案设计,管理制度太原工业学院计算机工程系太原工业学院计算机工程系实验报告课程名称C#班级实验日期姓名学号实验成绩实验名称实验四数据库基本操作实验目的及要求1、掌握基本架构,能够通过Connection对象连接数据库。2、掌握通过DataReader进行数据查询的基本方法。3、掌握通过DataAdapter和DataSet进行数据查询的基本方法。4、掌握通过Command对象进行数据操作的基本方法。5、能够通过DataAdapter进行数据库操作。实验环境MicrosoftVisualStudio2010实验内容设计一个菜单系统;建立一个数据库,通过Connection对象连接数据库。通过DataAdapter和DataSet进行数据查询,通过Command对象进行数据操作,通过DataAdapter进行数据库操作,实现对数据的增删该查;要求界面友好。算法描述及实验步骤设计一个菜单系统界面;建立数据库information;通过Connection对象连接数据库;通过DataAdapter和DataSet进行数据查询;调试过程及实验结果添加菜品:查询菜品02删除菜品03总结通过本次实验,我了解到:设计思想是从数据库中读取数据到内存中,构成内存中的一个数据库。Connection对象:建立与特定数据源的连接Command对象:对数据源执行命令,公开Parameters,并且可以从Connection在Transaction的范围内执行DataReader对象:从数据源中读取只进且只读的数据流DataAdapter对象:用数据源填充DataSet并解析更新,DataAdapter是数据提供程序与DataSet的接口附录namespaceForm1{publicpartialclassmenu:Form{staticstringstr="server=localhost;UserId=root;password=;Database=information";MSqlConnectionmconn=newMSqlConnection(str);publicmenu(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){Stringsql="select*fromjibenxinxi";MSqlDataAdapterda=newMSqlDataAdapter(sql,mconn);DataSetds=newDataSet();(ds,"information");=ds;="information";[0].HeaderText="菜号";[1].HeaderText="菜名";[2].HeaderText="价格";[3].HeaderText="类别";[4].HeaderText="备注";[5].HeaderText="备注";();}privatevoidbutton1_Click(objectsender,EventArgse){newaddmenu().Visible=true;();}privatevoidbutton3_Click(objectsender,EventArgse){stringno=;if(no==""){Stringsql1="Select*fromjibenxinxi";MSqlDataAdapterda=newMSqlDataAdapter(sql1,mconn);DataSetds=newDataSet();(ds,"emploees");=ds;="emploees";();="";}else{stringsql=("select*fromjibenxinxiwhereno='{0}'",no);MSqlDataAdaptermda=newMSqlDataAdapter(sql,mconn);DataSetds=newDataSet();(ds,"emploees");=ds;="emploees";();="";}}privatevoidbutton2_Click(objectsender,EventArgse){Stringname=[Stringsql=("deletefromjibenxinxiwherename='{0}'",name);MSqlCommandmsqlcommand=newMSqlCommand(sql,mconn);();if()>0){("删除成功!!!");}Stringsql1="select*fromjibenxinxi";MSqlDataAdapterda=newMSqlDataAdapter(sql1,mconn);DataSetds=newDataSet();(ds,"emploees");=ds;="emploees";();}}}namespaceForm1{publicpartialclassaddmenu:Form{staticstringstr="server=localhost;UserId=root;password=root;Database=information";MSqlConnectionmcon=newMSqlConnection(str);publicaddmenu(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){Strings1=;Strings2=;Strings3=;Strings4=;Strings5=;Strings6=;stringconstr="server=localhost;UserId=root;password=;Database=information";MSqlConnectionmcon=newMSqlConnection(constr);();stringsql=("insertintojibenxinxivalues('{0}','{1}','{2}','{3}','{4}','{5}')",s1,s3,s,s4,s5,s6);MSqlCommandmcmd=newMSqlCommand(sql,mcon);tr{if()>0){("添加ó成功|!");=false;newmenu().Visible=true;}}catch(Exceptione1){;}();}}}namespaceTest{classProgram{staticvoidMain(string[]args){stringconstr="server=localhost;UserId=root;password=root;Database=information";MSqlConnectionmcon=newMSqlConnection(constr);();Stringsql="select*fromjibenxinxi";MSqlCommandmcmd=newMSqlCommand(sql,mcon);();MSqlDataReadermsr=();tr{while()){("菜号:{0}菜名:{1}价格:{2}类别:{3}备注:{4}备注:{5}",msr["no"],msr["name"],msr[

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论