Discovered bug in my software, Search / Listbox.

acidflash

Active member
Joined
Oct 23, 2008
Messages
29
Programming Experience
1-3
I am writing a vb.net program with ado and i just recently noticed a bug that i need to fix in my software, but i havent the slightest clue where to start. Basically, I have programmed a search button with the sql commad "SELECT * FROM X Where FirstName = '" & FirstName.text "' AND LastName ='" &LastName.text "'" ; it finds the entry based on firstname and lastname, and after that, i use oledb reader to read the entries into my textboxes, alongside this, i have a list box which is bound to the database and allows me to choose from the "FirstName" column. When pressing the "save" button on my software, i always refer to the command: ClientsDS.Tables("ClientsMain").Rows(ClientsInc).Item("FirstName") = FirstName.Text ;
the parameter .Rows, which I refer to in ClientInc, ClientInc = listbox.currentrow ;
when i search, and enter data into the textboxes based on result, and the listbox is previously highlighted/selected/pointed to another entry, it *always* and logically edits the listbox.currentrow instead of the entry that i got from the search.
required: I need to figure out a way to get the "currentrow" of the search entry and I havent the slightest clue where to start. Some pointers and examples would be VERY much appreciated.

acidflash
 
Solved!

Ok I solved the problem, here is the solution:

VB.NET:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim RecordUpdateCB As New OleDb.OleDbCommandBuilder(ClientsDA)
        Dim RecordUpdate As OleDb.OleDbCommand = New OleDb.OleDbCommand
        RecordUpdate.Connection = ClientsConnection
        RecordUpdate.CommandText = "UPDATE Clients SET FirstName = '" & FirstName.Text & "' , LastName = '" & LastName.Text & "' , Address = '" & Address.Text & "' , PhoneNumber = '" & PhoneNumber.Text & "' , FileNumber = '" & FileNumber.Text & "' WHERE FirstName= '" & PreviousFirstName & "' AND LastName ='" & PreviousLastName & "'"
        RecordUpdate.ExecuteNonQuery()
        ClientsDA.Update(ClientsDS, "ClientsMain")
        MessageBox.Show("")
        Me.Refresh()
    End Sub

PreviousFirstName is a global variable that is set 1) When the search finds the entry, OR 2) When listbox selectedindex changes.
PreviousLastName is the same, and it worked like a charm.

acidflash
 
What happens when the last name is O'Sullivan?

Take a read of the PQ link in my signature..
 
Back
Top