private void btnSave_Click(object sender, EventArgs e) { DateTime dateTime = dtpDOB.Value; const string after = "yyyyMMdd"; string password = dateTime.ToString(after); DatabaseConnertor databaseConnertor = new DatabaseConnertor(); databaseConnertor.connect(); addMedicalstaffs addMedicalstaffs = new addMedicalstaffs(); addMedicalstaffs.Ms_position = cbPositon.Text; addMedicalstaffs.Ms_firstName = tbFN.Text; addMedicalstaffs.Ms_lastName = tbLN.Text; addMedicalstaffs.Ms_dob = this.dtpDOB.Value; addMedicalstaffs.Ms_age = int.Parse(lbAge.Text); addMedicalstaffs.Ms_email = tbEmail.Text; addMedicalstaffs.Ms_contact = int.Parse(tbContact.Text); addMedicalstaffs.Ms_loginid = tbFN.Text + tbLN.Text; addMedicalstaffs.Ms_password = password; addMedicalstaffshandler addMedicalstaffsHandler = new addMedicalstaffshandler(); int recordCnt = addMedicalstaffsHandler.addNewMedicalStaff(databaseConnertor.getconn(), addMedicalstaffs); MessageBox.Show(recordCnt + " record has been inserted !!"); }
public int addNewMedicalStaff(MySqlConnection conn, addMedicalstaffs addMedicalStaff) { string sql = "INSERT INTO medicalstaff (ms_position, ms_firstName, ms_lastName, ms_age, ms_dob, ms_contact, ms_email, ms_loginid, ms_password)" + " VALUES ('" + addMedicalStaff.Ms_position + "', '" + addMedicalStaff.Ms_firstName + "', '" + addMedicalStaff.Ms_lastName + " ', " + addMedicalStaff.Ms_age + ", '" + addMedicalStaff.Ms_dob.ToString("yyyy-MM-dd") + " ', " + addMedicalStaff.Ms_contact + " , '" + addMedicalStaff.Ms_email + "' , '" + addMedicalStaff.Ms_loginid + " ', '" + addMedicalStaff.Ms_password + "')"; MySqlCommand sqlComm = new MySqlCommand(sql, conn); return(sqlComm.ExecuteNonQuery()); }