Access+Vs 数据库增删查改——(不使用使用Asp.net的sqldatasource控件)根据如下Universtiy.mdb数据库,处理学生注册选课与授课老师的工作

Access+Vs 数据库增删查改——根据如下Universtiy.mdb数据库,处理学生注册选课与授课老师的工作(不使用使用Asp.net的sqldatasource控件

一.题目

请根据如下Universtiy.mdb数据库,处理学生注册选课与授课老师的工作(mdb数据库会另外提供):
在这里插入图片描述
不使用Asp.net的sqldatasource控件完成以下页面:
(1) 可以使用dropdownlist的方式,以选择课程名称的查询方式,将列出选修课程学生的数据。(注意:无论任何学期offering此课程)
(2) 请对于教师(faculty)的数据表,写一网页达成查询数据(查询条件:firstname、city)、新增数据、修改数据、删除数据的功能。(注意:hiredate雇用日期,由于牵涉日期的处理较麻烦,同学可选择回避)


二.涉及知识

1.Access数据库——代码连接数据库

1)数据库连接,打开,关闭

   //连接字符串
    String sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Server.MapPath("APP_Data\\UniversityDB.mdb") + "; ";
    OleDbConnection myConnection = new OleDbConnection(sqlconn);
    //打开数据库连接
    myConnection.Open();
    myConnection.Close();//连接数据库,不支持ssl连接

2)数据库GridView1,DropDownList控件绑定

1.数据库操作指令——命令

student_data:sql语句(增删查改)
OleDbCommand myCommand1 = new OleDbCommand(student_data, myConnection);

2.适配器

OleDbDataAdapter Adapter1 = new OleDbDataAdapter();

3.数据集

DataSet myDs1 = new DataSet();

4.GridView控件绑定
	  GridView1.DataSource = myDs1;
	  GridView1.DataKeyNames = new String[] {
    "StdSSN", }; //设置关键字
	  GridView1.DataBind();
5.DropDownList控件绑定
      DropDownList1.DataSource = myDs3;
      DropDownList1.DataTextField = "CrsDesc";
      DropDownList1.DataValueField = "CrsDesc";
      DropDownList1.DataBind();
6.绑定学生表GridView1 例子,绑定课程表 DropDownList1 例子
 //绑定学生表GridView1
      string student_data = "select  * from student ";
      OleDbCommand myCommand1 = new OleDbCommand(student_data, myConnection);

      OleDbDataAdapter Adapter1 = new OleDbDataAdapter();
      Adapter1.SelectCommand = myCommand1;

      DataSet myDs1 = new DataSet();
      Adapter1.Fill(myDs1, "Readers");

      GridView1.DataSource = myDs1;
      GridView1.DataKeyNames = new String[] {
    "StdSSN", }; 
      //GridView1.DataKeyNames = new String[] { "id" };
      GridView1.DataBind();

//绑定课程表 cousre_name DropDownList1
      string course_data = "select distinct CrsDesc from Course ";
      OleDbCommand myCommand3 = new OleDbCommand(course_data, myConnection);

      OleDbDataAdapter Adapter3 = new OleDbDataAdapter();
      Adapter3.SelectCommand = myCommand3;

      DataSet myDs3 = new DataSet();
      Adapter3.Fill(myDs3);

      DropDownList1.DataSource = myDs3;
      DropDownList1.DataTextField = "CrsDesc";
      DropDownList1.DataValueField = "CrsDesc";
      DropDownList1.DataBind();

2.数据库语句,增删查改

增:insert 不用插入时间!!!

    string F2 = "INSERT INTO Faculty(FacSSN, FacFirstName, FacLastName, FacCity, FacState, FacDept, FacRank, FacSalary, FacSupervisor, FacZipCode)"
	            + "VALUES(" + A + "," + B + "," + C + "," + D + "," + E + "," + F + "," + G + "," + H + "," + I + "," + K + ")";	
    OleDbCommand myCommand = new OleDbCommand(F2, myConnection);

删:delete

	string str = "delete from faculty where FacSSN='" + GridView2.DataKeys[e.RowIndex].Value.ToString() + "'";
	OleDbCommand myCommand = new OleDbCommand(str, myConnection);

查:select

	string firstname_city = "select * from faculty ";
	OleDbCommand myCommand2 = new OleDbCommand(firstname_city, myConnection);

改:update不用修改时间!!!

	string str = "update faculty set FacFirstName = '" + B + "',FacLastName = '" + C + "', FacCity = '" + D + "', FacState = '" + E + "',FacRank = '" + F + "', FacDept = '" + G + "',FacSalary = '" + H + "', FacSupervisor = '" + I + "', FacZipCode='" + K + "'  WHERE (FacSSN ='" + A + "')";
	OleDbCommand myCommand = new OleDbCommand(str, myConnection);

三.运行截图

加载页面(将全部功能都放在了一个网页)
在这里插入图片描述


根据 课程名称 查询 选修该课程的学生
在这里插入图片描述


查询符合 firstname,或者city 条件的faculty数据
在这里插入图片描述


修改 faculty表 内容,编辑–>改内容–>更新
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


新增 faculty表内容,填写 新增数据填写表单
在这里插入图片描述
在这里插入图片描述


四.代码实现

html 代码

在这里插入图片描述

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Universtiy2.aspx.cs" Inherits="homework_6.Universtiy2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>

    <style>
        .label1_stytle
        {
     
            display: inline-block;
            width: 180px;
            margin-bottom: 15px;
            margin-left: 15px;
        }

         .div_add {
     
            border: solid #000000; /*设置边框样式跟颜色*/
            border-width: 1px; /*设置边框宽度*/
            width: 500px; /*设置div宽度*/
            margin-bottom: 30px;
            height: 500px; /*设置div高度*/
           
        }

         

        .div{
     
        border: solid #000000; /*设置边框样式跟颜色*/
        border-width: 1px; /*设置边框宽度*/
        width: auto; /*设置div宽度*/
        margin-bottom: 30px;
        height: auto; /*设置div高度*/
           
    }

    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="div">
             <asp:Label ID="Label16" runat="server" Text="student表查询:" style="margin:15px;font-weight:bold;"  Width="198px"></asp:Label>         
             <br />
            <asp:Label ID="Label1" runat="server" Text="课程名称"></asp:Label>
            <asp:DropDownList ID="DropDownList1" runat="server" >
            </asp:DropDownList>
            <asp:Button ID="Button1" runat="server" Text="查询" OnClick="Button1_Click"  />
            <asp:Button ID="Button5" runat="server" Text="浏览全部" OnClick="Button5_Click" />
           
             
            <br />
            <br />

        <asp:GridView ID="GridView1" runat="server" >
            
        </asp:GridView>

            <br />

            </div>

        <div class ="div">
            <div >
             <asp:Label ID="Label15" runat="server" Text="faculty表查询:" style="margin:15px;font-weight:bold;"  Width="198px"></asp:Label>         
             <br />
             <asp:Label ID="Label2" runat="server" Text="firstname" class="label1_stytle"></asp:Label>
           
             <asp:DropDownList ID="DropDownList2" runat="server" >
             </asp:DropDownList>
           
            <br />
             <asp:Label ID="Label3" runat="server" Text
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值