예제 #1
0
파일: Class1.cs 프로젝트: ts04670223/HR-MVC
        public Experiences GetByExp(int id)
        {
            Experiences   experience    = new Experiences();
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand("SELECT * FROM experience WHERE basicInformationID = @id");

            sqlCommand.Connection = sqlConnection;
            sqlCommand.Parameters.Add(new SqlParameter("@id", id));
            sqlConnection.Open();
            SqlDataReader reader = sqlCommand.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    experience = new Experiences
                    {
                        ID                 = reader.GetInt32(reader.GetOrdinal("id")),
                        ServiceUnit        = reader.GetString(reader.GetOrdinal("serviceUnit")),
                        Title              = reader.GetString(reader.GetOrdinal("title")),
                        JobDescription     = reader.GetString(reader.GetOrdinal("jobDescription")),
                        Start              = reader.GetString(reader.GetOrdinal("start")),
                        Finish             = reader.GetString(reader.GetOrdinal("finish")),
                        BasicInformationID = reader.GetInt32(reader.GetOrdinal("basicInformationID")),
                    };
                }
            }
            else
            {
                experience.Title = "未找到資料";
            }
            sqlConnection.Close();
            return(experience);
        }
예제 #2
0
파일: Class1.cs 프로젝트: ts04670223/HR-MVC
        public void UpdateExperiences(Experiences experience)
        {
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand(
                @"UPDATE experience SET serviceUnit = @serviceUnit, title = @title, jobDescription = @jobDescription, start = @start, finish = @finish WHERE basicInformationID = @id");

            sqlCommand.Connection = sqlConnection;
            sqlCommand.Parameters.Add(new SqlParameter("@serviceUnit", experience.ServiceUnit));
            sqlCommand.Parameters.Add(new SqlParameter("@title", experience.Title));
            sqlCommand.Parameters.Add(new SqlParameter("@jobDescription", experience.JobDescription));
            sqlCommand.Parameters.Add(new SqlParameter("@start", experience.Start));
            sqlCommand.Parameters.Add(new SqlParameter("@finish", experience.Finish));
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
        }
예제 #3
0
파일: Class1.cs 프로젝트: ts04670223/HR-MVC
        public void CreateExperience(Experiences basicInformation)
        {
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand(
                @"INSERT INTO  experience (serviceUnit,title,jobDescription,start,finish,basicInformationID)
                  VALUES(@serviceUnit,@title,@jobDescription,@start,@finish,@basicInformationID )");

            sqlCommand.Connection = sqlConnection;
            sqlCommand.Parameters.Add(new SqlParameter("@serviceUnit", basicInformation.ServiceUnit));
            sqlCommand.Parameters.Add(new SqlParameter("@title", basicInformation.Title));
            sqlCommand.Parameters.Add(new SqlParameter("@jobDescription", basicInformation.JobDescription));
            sqlCommand.Parameters.Add(new SqlParameter("@start", basicInformation.Start));
            sqlCommand.Parameters.Add(new SqlParameter("@finish", basicInformation.Finish));
            sqlCommand.Parameters.Add(new SqlParameter("@basicInformationID", basicInformation.BasicInformationID));
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
        }