资源简介

VS中c#中数据库的操作,包括数据库的连接,增删查改 题目:实现一个简单的员工组织结构管理系统 1.数据库设计 1)员工表(工号,姓名,性别,所属部门,职位) 2)部门表(部门名称,部门简介) 3)管理表(员工工号,管辖部门名称) 2.完成如下功能 1)新增员工 2)删除员工 3)员工部门调转 4)员工职务调动 5)设置部门 6)设置部门的部长 7)删除部门 8)添加员工管辖部门 9)查询所有部门(部门名称,部门简介,部长姓名)

资源截图

代码片段和文件信息

namespace MySqlData20180720
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    class MySqlConnection
    {
        private static string mySqlConnection = “Data Source=dragonma;Initial Catalog=MyDatabase2018072001;Integrated Security=True“;
        public void ShowTable(string what)
        {
            try
            {
                SqlConnection connection = new SqlConnection(@mySqlConnection);
                string sqlStr = String.Format(“select * from {0}“ what);
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlStr connection);
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    for (int i = 0; i < rdr.FieldCount; i++)
                    {
                        Console.Write(rdr[i].ToString() + “   “);

                    }
                    Console.WriteLine();
                }
                rdr.Close();
                connection.Close();
            }
            catch (Exception e)
            {

                Console.WriteLine(“select failed“);
                WriteLog(e.Message);
            }
        }
        public void SelectAll(string str)
        {
            try
            {
                SqlConnection connection = new SqlConnection(@mySqlConnection);
                connection.Open();
                SqlCommand cmd = new SqlCommand(@str connection);
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    for (int i = 0; i < rdr.FieldCount; i++)
                    {
                        Console.Write(rdr[i].ToString() + “   “);

                    }
                    Console.WriteLine();
                }
                rdr.Close();
                connection.Close();
            }
            catch (Exception e)
            {

                Console.WriteLine(“select failed“);
                WriteLog(e.Message);
            }
        }
        /// 
        /// operator employeeTable
        /// 

        /// 
        /// 
        /// 
        /// 
        public void InsertEmployee(string name string sex string departmentName string job)
        {
            try
            {
                if (name != null && sex != null)
                {
                    if (job != “manage“)
                    {
                        SqlConnection connection = new SqlConnection(@mySqlConnection);
                        connection.Open();
                        string sqlStr = String.Format(“insert into employeeTable(idnamesexdepa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2138  2018-08-29 09:14  工作\code\20180720 MySql\2018082901 MySqlConnection\Test.cs
     文件       15631  2018-08-29 09:14  工作\code\20180720 MySql\2018082901 MySqlConnection\MySqlConnection.cs

评论

共有 条评论