Problems updating database
-
I added a student to the database when in debug mode, but when I exit out of debug mode and then go back into debug mode the new student record is not there. Do you know why? Do I need to commit the changes to the database? I am using acceptChanges. I also add lesson information for the student. When I try to add the lesson information it doesn't even add to the database. Why does the student add but not the lesson? When I used a message box to display the lesson info it displayed. Here is my code to add the student.
addRow = lpDataSet.tbl_students.Newtbl_studentsRow() addRow("stud_name") = txtStudentName.Text addRow("stud_par_name") = txtParentName.Text addRow("stud_add") = txtStudAdd.Text addRow("stud_unit_num") = txtAptNum.Text addRow("stud_city") = txtCity.Text addRow("stud_state") = txtState.Text addRow("stud_zip") = Convert.ToInt32(txtZip.Text) addRow("stud_email") = txtEmail.Text addRow("stud_cell") = txtStudCell.Text addRow("stud_phone") = txtStudPhone.Text addRow("stud_status") = intStudStat lpDataSet.tbl_students.Rows.Add(addRow) studTableAdapter.Update(addRow) lpDataSet.Tables("tbl_students").AcceptChanges()
Here is the code to add the lesson.addRow = lpDataSet.tbl_lessons.Newtbl_lessonsRow() addRow("less_instrument") = txtInstrument.Text addRow("stud_id") = Convert.ToInt32(cboSelectStudent.SelectedValue) addRow("less_start_date") = Convert.ToDateTime(dtpStartDate.Text) addRow("less_end_date") = Convert.ToDateTime(dtpEndDate.Text) addRow("less_time") = Convert.ToDateTime(lvwItem.SubItems(1).Text) addRow("less_day") = intDay addRow("teach_id") = Convert.ToInt32(cboSelectTeacher.SelectedValue) addRow("less_status") = intLessStat lpDataSet.tbl_lessons.Rows.Add(addRow) lessonTableAdapter.Update(addRow) lpDataSet.Tables("tbl_lessons").AcceptChanges()
-
I added a student to the database when in debug mode, but when I exit out of debug mode and then go back into debug mode the new student record is not there. Do you know why? Do I need to commit the changes to the database? I am using acceptChanges. I also add lesson information for the student. When I try to add the lesson information it doesn't even add to the database. Why does the student add but not the lesson? When I used a message box to display the lesson info it displayed. Here is my code to add the student.
addRow = lpDataSet.tbl_students.Newtbl_studentsRow() addRow("stud_name") = txtStudentName.Text addRow("stud_par_name") = txtParentName.Text addRow("stud_add") = txtStudAdd.Text addRow("stud_unit_num") = txtAptNum.Text addRow("stud_city") = txtCity.Text addRow("stud_state") = txtState.Text addRow("stud_zip") = Convert.ToInt32(txtZip.Text) addRow("stud_email") = txtEmail.Text addRow("stud_cell") = txtStudCell.Text addRow("stud_phone") = txtStudPhone.Text addRow("stud_status") = intStudStat lpDataSet.tbl_students.Rows.Add(addRow) studTableAdapter.Update(addRow) lpDataSet.Tables("tbl_students").AcceptChanges()
Here is the code to add the lesson.addRow = lpDataSet.tbl_lessons.Newtbl_lessonsRow() addRow("less_instrument") = txtInstrument.Text addRow("stud_id") = Convert.ToInt32(cboSelectStudent.SelectedValue) addRow("less_start_date") = Convert.ToDateTime(dtpStartDate.Text) addRow("less_end_date") = Convert.ToDateTime(dtpEndDate.Text) addRow("less_time") = Convert.ToDateTime(lvwItem.SubItems(1).Text) addRow("less_day") = intDay addRow("teach_id") = Convert.ToInt32(cboSelectTeacher.SelectedValue) addRow("less_status") = intLessStat lpDataSet.tbl_lessons.Rows.Add(addRow) lessonTableAdapter.Update(addRow) lpDataSet.Tables("tbl_lessons").AcceptChanges()
You're using an Access database as the datastore, correct? In your project, under the Solution Explorer, you should find your .MDB file somewhere. Click on it and, in the Properties window, you should find an option called "Copy to Output Directory". If this is set to "Copy always", Visual Studio is copying your test database to the Debug or Release folder every time you run your app. This copy is what your code is modifying. The next time you to run your app, the original database file you created is copied to the Debug or Release folder again, overwriting anny changes your code made during the previous run.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008