Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problems updating database

Problems updating database

Scheduled Pinned Locked Moved Visual Basic
questiondatabasedebuggingannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AAGTHosting
    wrote on last edited by
    #1

    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()

    D 1 Reply Last reply
    0
    • A AAGTHosting

      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()

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups