DAL/StudentDAL.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using Model;

namespace DAL
{
    public class StudentDAL
    {
        public bool InsertOneRecord(Student student)
        {
            // 1. 创建连接
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["XDF"].ConnectionString);

            // 2. 打开连接
            connection.Open();

            // 2.1 创建命令对象
            SqlCommand command = new SqlCommand("INSERT INTO Student(StuID, StuName, Password, Sex,  Grade,  Email, Phone,BaseID) VALUES(@StuID, @StuName, @Password, @Sex, @Grade,  @Email, @Phone,@BaseID)", connection);
            command.Parameters.AddWithValue("@StuID", student.StuID);
            command.Parameters.AddWithValue("@StuName", student.StuName);
            command.Parameters.AddWithValue("@Password", student.Password);
            command.Parameters.AddWithValue("@Sex", student.Sex);
           
            command.Parameters.AddWithValue("@Grade", student.Grade);
            command.Parameters.AddWithValue("@BaseID", student.BaseID);
            command.Parameters.AddWithValue("@Email", student.Email);
            command.Parameters.AddWithValue("@Phone", student.Phone);

            // 2.2 执行命令对象
            int result = command.ExecuteNonQuery();

            // 3. 关闭连接
            connection.Close();

            return (result == 1);
        }
        public bool ResetPassword(Student student)
        {
            // 1. 创建连接
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["XDF"].ConnectionString);

            // 2. 打开连接
            connection.Open();

            // 2.1 创建命令对象
            SqlCommand command = new SqlCommand("UPDATE Student SET Password='111111' WHERE StuID=@StuID", connection);
            command.Parameters.AddWithValue("@StuID", student.StuID);
            
            

            // 2.2 执行命令对象
            int result = command.ExecuteNonQuery();

            // 3. 关闭连接
            connection.Close();

后面还有 102 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。