コード例 #1
0
        public bool Insert(DALSemester semester)
        {
            using (var connection = new SQLiteConnection(connectionString))
            {
                SQLiteCommand command = new SQLiteCommand(null, connection);
                int           res     = -1;
                try
                {
                    connection.Open();

                    command.CommandText = $"INSERT INTO {SemsterTableName} ({DALSemester.SemesterNumberColumn} ,{DALSemester.SemesterCreditColumn},{DALSemester.SemesterAverageColumn},{DALSemester.SemesterYearColumn},{DALSemester.SemesterDegreeColumn},{DALSemester.SemesterStudentIdColumn}) " +
                                          $"VALUES (@numVal,@creditVal,@averageVal@yearVal,@degreeVal,@studentIdVal);";


                    SQLiteParameter nameParam      = new SQLiteParameter(@"numVal", semester.Number);
                    SQLiteParameter creditParam    = new SQLiteParameter(@"creditVal", semester.Credit);
                    SQLiteParameter averageParam   = new SQLiteParameter(@"averageVal", semester.Average);
                    SQLiteParameter yearParam      = new SQLiteParameter(@"yearVal", semester.Year);
                    SQLiteParameter degreeParam    = new SQLiteParameter(@"degreeVal", semester.Degree);
                    SQLiteParameter studentIdParam = new SQLiteParameter(@"studentIdVal", semester.StudentId);
                    command.Parameters.Add(nameParam);
                    command.Parameters.Add(creditParam);
                    command.Parameters.Add(averageParam);
                    command.Parameters.Add(yearParam);
                    command.Parameters.Add(degreeParam);
                    command.Parameters.Add(studentIdParam);

                    command.Prepare();
                    res = command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    if (e.Message != null)
                    {
                    }
                }
                finally
                {
                    command.Dispose();
                    connection.Close();
                }

                return(res > 0);
            }
        }
コード例 #2
0
        protected override DALObj ConvertReaderToObject(SQLiteDataReader reader)
        {
            DALSemester ret = new DALSemester(reader.GetInt32(0), reader.GetInt32(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4), reader.GetInt32(5));

            return(ret);
        }