コード例 #1
0
        private static int DoRegisterNewTeacherindb(TeacherInfo NewTeacher)
        {
            int returnVal = 0;
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
            try
            {
                //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();

                //define the connection used by the command object
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "INSERT INTO teacher(id,name,joinDate,tdob,address,phone,email,jobId,faculty,salary) " +
                                    "VALUES(@id,@name,@joinDate,@tdob,@address,@phone,@email,@jobId,@faculty,@salary)";

                //msqlCommand.CommandText = "INSERT INTO teacher(id,name,guardian,address,phone,dob,bloodGroup,joinClass,schoolFrom,joinDate) " +
                //                   "VALUES(@id,@name,@guardian,@address,@phone,@dob,@bloodGroup,@joinClass,@schoolFrom,@joinDate)";

                msqlCommand.Parameters.AddWithValue("@id", NewTeacher.id);
                msqlCommand.Parameters.AddWithValue("@name", NewTeacher.name);
                msqlCommand.Parameters.AddWithValue("@joinDate", NewTeacher.joinDate);
                msqlCommand.Parameters.AddWithValue("@tdob", NewTeacher.tdob);
                msqlCommand.Parameters.AddWithValue("@address", NewTeacher.address);
                msqlCommand.Parameters.AddWithValue("@phone", NewTeacher.phone);
                msqlCommand.Parameters.AddWithValue("@email", NewTeacher.email);
                msqlCommand.Parameters.AddWithValue("@jobId", NewTeacher.jobId);
                msqlCommand.Parameters.AddWithValue("@faculty", NewTeacher.faculty);
                msqlCommand.Parameters.AddWithValue("@salary", NewTeacher.salary);

                msqlCommand.ExecuteNonQuery();

                returnVal = 1;
            }
            catch (Exception er)
            {
                returnVal = 0;
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return returnVal;
        }
コード例 #2
0
        private static List<TeacherInfo> QueryAllTeacherList()
        {
            List<TeacherInfo> TeacherList = new List<TeacherInfo>();

            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "Select * From teacher ;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    TeacherInfo Teacher = new TeacherInfo();

                    Teacher.id = msqlReader.GetString("id");
                    Teacher.name = msqlReader.GetString("name");
                    Teacher.joinDate = msqlReader.GetDateTime("joinDate");
                    Teacher.tdob = msqlReader.GetDateTime("tdob");
                    Teacher.address = msqlReader.GetString("address");
                    Teacher.phone = msqlReader.GetString("phone");
                    Teacher.email = msqlReader.GetString("email");
                    Teacher.jobId = msqlReader.GetString("jobId");
                    Teacher.faculty = msqlReader.GetString("faculty");
                    Teacher.salary = msqlReader.GetString("salary");

                    TeacherList.Add(Teacher);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return TeacherList;
        }
コード例 #3
0
 public static int RegisterNewTeacher(TeacherInfo NewTeacher)
 {
     return DoRegisterNewTeacherindb(NewTeacher);
 }