C语言&SQl学生管理系统的功能

管理员的其他功能,增加数据库表内容 和 替换内容,以及学生查询相关信息
student
SELECT TOP 1000 [Sno]
,[Ssname]
,[Ssex]
,[Sage]
,[Sdept]
FROM [lmq].[dbo].[Student]
201215121 李勇 男 20 CS
201215122 刘晨 女 19 CS
201215123 王敏 女 18 MA
201215125 张丽 男 19 IS

course
SELECT TOP 1000 [Cno]
,[Cname]
,[Cpno]
,[Ccredit]
FROM [lmq].[dbo].[Course]
1 数据库 5 4
2 数学 2
3 信息系统 1 4
4 操作系统 6 3
5 数据结构 7 4
6 数据处理 2
7 PASCAL语言 6 4

sc
SELECT TOP 1000 [Sno]
,[Cno]
,[Grade]
FROM [lmq].[dbo].[Sc]
201215121 1 92
201215121 2 85
201215121 3 88
201215122 2 90
201215122 3 80


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

namespace 课程管理系统
{
    class Program
    {
      
        static void Main(string[] args)
        {

            int choice = 0;


            Console.WriteLine("**************************************************");
            Console.WriteLine("*********     欢迎进入教务管理系统        ********");
            Console.WriteLine("*********        请选择你的身份           ********");
            Console.WriteLine("*********          1--管理员              ********");
            Console.WriteLine("*********          2--学 生               ********");
            Console.WriteLine("*********          3--教 师               ********");
            Console.WriteLine("*********          0--退出系统            ********");
            Console.WriteLine("**************************************************");


            choice = int.Parse(Console.ReadLine());
            while (true)
            {

                switch (choice)
                {
                    case 1:
                        {
                            // authentication();扩展以后,可以对此函数对每个角色进行权限检查
                            Administrator();
                            break;
                        }
                    //case 2: break;
                    //case 3: break;
                    case 0: return;
                    default:
                        {
                            Console.WriteLine("输入错误,请重新选择");
                            choice = int.Parse(Console.ReadLine()); break;
                        }
                }

            } // end of while
        }// end of main

        
        //管理员相关的模块函数
        public static void Administrator()
        {

           int choice1 = 0;
           string sno;
            
            
            
       
         
            Console.WriteLine("*********       请选择你需要的操作        ********");
            Console.WriteLine("*********          1--浏览数据库          ********");
            Console.WriteLine("*********          2--增加数据库信息      ********");
            Console.WriteLine("*********          3--修改数据库信息      ********");
            Console.WriteLine("*********          4--删除数据库信息      ********");
            Console.WriteLine("*********          0--退出系统            ********");
            Console.WriteLine("**************************************************");

            

            choice1 = int.Parse(Console.ReadLine());
            
            switch (choice1)
            {
                  
                
                //数据库的浏览操作
                case 1:
                {
                        
                                                
                        SqlConnection con1 = new SqlConnection(); //创建数据库连接

                        String con = "server=.;database=D:\\SQL_data\\lmq.MDF;integrated security=SSPI;MultipleActiveResultSets=true;"; //定义数据库连接信息
                        con1.ConnectionString = con;
                        if (con1.State == ConnectionState.Closed)
                       {
                            //打开链接
                            con1.Open();//打开数据库
                            Console.WriteLine("已连接到课程管理数据库");
                        
                        }
         
                        string sqlStr = "select * from dbo.Student";

                        SqlCommand comm = new SqlCommand(sqlStr, con1);

                        SqlDataReader sdr = null;

                        try
                       {
                           Console.WriteLine("学号:       姓名               性别        年龄    所在系");
                           
                           sdr = comm.ExecuteReader();
                           while (sdr.Read())
                           {
                               Console.WriteLine(sdr["Sno"].ToString() + "    " + sdr["Sname"] + sdr["Ssex"] + "         " + sdr["Sage"].ToString() +  "      " +sdr["Sdept"].ToString());

                           }
                        }
                        catch (Exception ex)
                       {
                           Console.WriteLine(ex.Message);
                       }
                      finally
                      {
                         con1.Close();
                      }
                        Console.Read();

                        con1.Close();  
                        break;
                 }

               
                //数据库的删除操作
                 case 4:
                 {
                                                                    
                        //1.创建连接字符串
                        string constr = "server=.;database=D:\\SQL_data\\lmq.MDF;integrated security=SSPI;MultipleActiveResultSets=true;";
                        //2.连接对象
                        using (SqlConnection con = new SqlConnection(constr))
                        {
                            //3.sql语句
                            Console.WriteLine("请输入要删除的学生学号");
                            sno= Console.ReadLine();
                            string sql = "delete from dbo.Student where Sno='" + sno + "'"; 
                           //4.创建sqlcommand对象
                           using (SqlCommand cmd = new SqlCommand(sql, con))
                            {
                              //5.打开数据库连接
                                con.Open();
                              //6.执行数据库语句
                             int r = cmd.ExecuteNonQuery();
                             Console.WriteLine("成功删除了{0}行数据", r);
                            }
                         }
                         Console.ReadKey();



                        //显示删除后的结果


                        SqlConnection con1 = new SqlConnection(); //创建数据库连接

                        String conn = "server=.;database=D:\\SQL_data\\.MDF;integrated security=SSPI;MultipleActiveResultSets=true;"; //定义数据库连接信息
                        con1.ConnectionString = conn;
                        if (con1.State == ConnectionState.Closed)
                        {
                            //打开链接
                            con1.Open();//打开数据库
                            Console.WriteLine("已连接到课程管理数据库");

                        }

                        Console.WriteLine("删除后的学生新数据为");
                        string sqlStr = "select Sno from dbo.Student";

                        SqlCommand comm = new SqlCommand(sqlStr, con1);

                        SqlDataReader sdr = null;

                        try
                        {
                            sdr = comm.ExecuteReader();
                            while (sdr.Read())
                            {
                                Console.WriteLine("学号:" + sdr["Sno"].ToString());

                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            con1.Close();
                        }
                        Console.Read();

                        con1.Close();
                        break;
                    }
                    //case 2: break;
                    //case 3: break;
                   // case 0: return;
                   
              }

                                
            System.Environment.Exit(0);

        }//switch开关语句结束

    } //管理员相关的模块函数结束
}

增加管理员的其他功能,增加数据库表内容 和 替换数据库表内容,以及学生查询自己的选课信息

参考其他模块写,无非sql语句不一样。

不会写SQL语句