实验八 访问数据库应用实例.doc

实验八 访问数据库应用实例.doc

ID:57099000

大小:171.00 KB

页数:5页

时间:2020-08-02

实验八 访问数据库应用实例.doc_第1页
实验八 访问数据库应用实例.doc_第2页
实验八 访问数据库应用实例.doc_第3页
实验八 访问数据库应用实例.doc_第4页
实验八 访问数据库应用实例.doc_第5页
资源描述:

《实验八 访问数据库应用实例.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、实验八访问数据库应用实例一.实验目的:能够熟练运用某种高级语言进行数据库编程二.实验内容:根据上次实验所使用的组件,编写一个访问数据库的程序,要求该程序具备查询、插入、删除、修改四个基本功能。三.实验过程:(将程序的实验过程简单描述并将相关界面截图,关键代码附在文中)usingSystem;usingSystem.Data;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data.SqlClient;namespaceConsoleApplication2{clas

2、sProgram{staticvoidMain(string[]args){stringconnstr=string.Format("server=LIUYAN\SQLEXPRESS;database=学生课程数据库;uid=login;pwd=123456");Console.WriteLine("----------访问数据库系统-----------");Console.Write("-----------请输入操作:");intOperator=Convert.ToInt32(Console.ReadLine());switch(Operator){case1:

3、Select(connstr);break;case2:Add(connstr);break;case3:Delect(connstr);break;case4:Update(connstr);break;default:break;}}staticvoidSelect(strings){SqlConnectionconn=newSqlConnection(s);conn.Open();SqlCommandcomm=newSqlCommand();comm.Connection=conn;Console.Write("输入要查询的学生姓名:");stringname=st

4、ring.Format(Console.ReadLine());comm.CommandText=string.Format("select*fromstudentwheresname='{0}'",name);comm.CommandType=CommandType.Text;SqlDataReadersdr=comm.ExecuteReader();while(sdr.Read()){Console.WriteLine("学号;"+sdr[0].ToString());Console.WriteLine("姓名;"+sdr[1].ToString());Console

5、.WriteLine("年龄;"+sdr[2].ToString());Console.WriteLine("院系;"+sdr[3].ToString());Console.WriteLine("生日;"+sdr[4].ToString());}conn.Dispose();}staticvoidAdd(strings){SqlConnectionconn=newSqlConnection(s);conn.Open();SqlCommandcomm=newSqlCommand();comm.Connection=conn;Console.Write("输入要插入的学生学号

6、:");stringno=string.Format(Console.ReadLine());Console.Write("输入要插入的学生姓名:");stringname=string.Format(Console.ReadLine());Console.Write("输入要插入的学生年龄:");intage=Convert.ToInt32(Console.ReadLine());Console.Write("输入要插入的学生系别:");stringdept=string.Format(Console.ReadLine());Console.Write("输入要插入的学

7、生生日:");stringbirthday=string.Format(Console.ReadLine());comm.CommandText=string.Format("InsertIntostudent(sno,sname,sage,sdept,sbirthday)values({0},'{1}',{2},'{3}',{4})",no,name,age,dept,birthday);comm.CommandType=CommandType.Text;if(comm.ExecuteNonQuery()>0){Consol

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。