Beispiel #1
0
        public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
        /// <summary> 
        /// 添加数据 
        /// </summary> 
        /// <returns></returns> 
        public int Add(AgentExam entity)
        {


            string sql = "INSERT INTO tb_agent_exam (userId,exam_sequence,duration,status,scoreSummary)";
            sql = sql + " VALUE (@userId,@exam_sequence,@duration,@status,@scoreSummary)";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@userId", entity.userId);
                command.Parameters.AddWithValue("@exam_sequence", entity.exam_sequence);
                command.Parameters.AddWithValue("@duration", entity.duration);
                command.Parameters.AddWithValue("@status", entity.status);
                command.Parameters.AddWithValue("@scoreSummary", entity.scoreSummary);


                int i = command.ExecuteNonQuery();
                mycn.Close();
                mycn.Dispose();
                return i;
            }
        }
Beispiel #2
0
        /// <summary> 
        /// 根据主键查询 
        /// </summary> 
        /// <param name="primaryKey"></param> 
        /// <returns></returns> 
        public AgentExam Get(String examSeq, String userId)
        {
            string sql = "SELECT exam_sequence,userId,status,scoreSummary,duration from tb_agent_exam WHERE exam_sequence=@examSeq and userId=@userId";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@examSeq", examSeq);
                command.Parameters.AddWithValue("@userId", userId);
                MySqlDataReader reader = command.ExecuteReader();

                AgentExam exam = null;
                if (reader.Read())
                {
                    exam = new AgentExam();
                    exam.exam_sequence = reader["exam_sequence"] == DBNull.Value ? null : reader["exam_sequence"].ToString();
                    exam.userId = reader["userId"] == DBNull.Value ? null : reader["userId"].ToString();
                    exam.status = reader["status"] == DBNull.Value ? null : reader["status"].ToString();
                    exam.scoreSummary = reader["scoreSummary"] == DBNull.Value ? null : reader["scoreSummary"].ToString();
                    exam.duration = reader["duration"] == DBNull.Value ? null : reader["duration"].ToString();
                    

                }
                mycn.Close();
                return exam;
            }

        }