none
Trying to search DataSet by recently updated field fails. RRS feed

  • Question

  • Hi,

     

    I've got a simple VB .NET app that interacts with a db to pull info about students and display it on-screen.

     

    The user searches by a parameter like Name or Birthdate, clicks "Find", and a new form opens displaying some information about that student. This info can then be edited, and an "Update" button sends the changed info back to the db. However, if I edit one of the searchable parameters, like the student's name, something unexpected happens.

     

    Closing the information form and then searching for the new name returns 0 results. Searching for the old name brings up the information form, but all the fields that should contain info are blank. Searching by a different parameter, such as the student's birthdate, brings up all the information, including the new name.

     

    As well, if I completely close the program and restart it, searching for the new name displays all the info and the new name without any problems.

     

    Here's the code for the Update button:

     

    Code Snippet

    Private Sub btnUpdate_Click(ByVal sender As System.Object, _

     ByVal e As System.EventArgs) Handles btnUpdate.Click

         Me.StudentsBindingSource.EndEdit()

         If CambridgeStudentsDataSet.Students.GetChanges() IsNot Nothing Then

              Me.StudentsTableAdapter.Update(CambridgeStudentsDataSet.Students.GetChanges())

              MessageBox.Show("Student info updated.")

         End If

    End Sub

     

    I should also mention that the Name is NOT a primary key.

     

    Also, here's the code for the Find button that performs the search:

     

    Code Snippet

    Private Sub btnStuFind_Click(ByVal sender As System.Object, _

     ByVal e As System.EventArgs) Handles btnStuFind.Click

     

       Dim filteredView As Data.DataView = New Data.DataView( _ 

       CambridgeStudentsDataSet.Students)

       filteredView.RowFilter = "EName Like '%" + txtEName.Text + "%'"

     

       Dim rowsFound As Int32 = filteredView.Count

       Select Case rowsFound

          Case 0 ' no records found

             MessageBox.Show( _

             "No matching records found", _

             "No records found", _

             MessageBoxButtons.OK, _

             MessageBoxIcon.Exclamation)

          Case 1

             frmStudentDetails.NameParameter = _

             filteredView.Item(0)("EName")

             frmStudentDetails.Show()

       End Select

    End Sub

     

     

    It seems that most people having issues with data updates are experiencing very different issues, so I thought I'd run this by everyone and see if there's something obvious I'm doing wrong here.

     

    Thanks,

    Jon Keefe

    Sunday, July 1, 2007 4:14 PM