Exemplo n.º 1
0
        public Educations GetByEdu(int id)
        {
            Educations    education     = new Educations();
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand("SELECT * FROM education 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())
                {
                    education = new Educations
                    {
                        ID                 = reader.GetInt32(reader.GetOrdinal("id")),
                        Degree             = reader.GetString(reader.GetOrdinal("degree")),
                        School             = reader.GetString(reader.GetOrdinal("school")),
                        Department         = reader.GetString(reader.GetOrdinal("department")),
                        BasicInformationID = reader.GetInt32(reader.GetOrdinal("basicInformationID")),
                    };
                }
            }
            else
            {
                education.Department = "未找到資料";
            }
            sqlConnection.Close();
            return(education);
        }
Exemplo n.º 2
0
        public void UpdateEducations(Educations education)
        {
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand(
                @"UPDATE education SET degree = @degree, school = @school, department = @department WHERE basicInformationID = @id");

            sqlCommand.Connection = sqlConnection;
            sqlCommand.Parameters.Add(new SqlParameter("@degree", education.Degree));
            sqlCommand.Parameters.Add(new SqlParameter("@school", education.School));
            sqlCommand.Parameters.Add(new SqlParameter("@department", education.Department));
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
        }
Exemplo n.º 3
0
        public void CreateEducation(Educations BasicInformation)
        {
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_DBconnect"].ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand(
                @"INSERT INTO  education (degree,school,department,basicInformationID)
                  VALUES(@degree,@school,@department,@basicInformationID)");

            sqlCommand.Connection = sqlConnection;
            sqlCommand.Parameters.Add(new SqlParameter("@degree", BasicInformation.Degree));
            sqlCommand.Parameters.Add(new SqlParameter("@school", BasicInformation.School));
            sqlCommand.Parameters.Add(new SqlParameter("@department", BasicInformation.Department));
            sqlCommand.Parameters.Add(new SqlParameter("@basicInformationID", BasicInformation.BasicInformationID));
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
        }