Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie question about updating datarow

Status
Not open for further replies.

herbally

Programmer
Jun 13, 2008
8
US
I have a membership app that read driver's license info and adds/updates members in the access database. I'm using a dataview to filter the dataset and figure out whether or not the person already exists in the database, but I'm unclear how to programatically update their info if they do exist in the database and their information has changed.

I'm sure this is simple, but the code that I've found in the MS Press book only uses .rows(0) as an example, but I don't know the index of the row in question...only that it does exist.
 
Obviously I already have considering that I mentioned my dataset which is filled with a dataadapter and that I read in the press book about modifying datarows.....what eludes me is how to go about modifying a certain datarow with using the row index since that changes....
 
You should be able to update the dataview directly.

You mentioned that you are doing a filter on the dataview. If you can be certain that only one record is returned on a match, you can update your dataview like this (assuming the dataview is called DataView1):

DataView1(0).Item("Fieldname") = "New Value"

The "(0)" in this code is the same as ".Rows(0)" - it references an index in the dataview. If you only have one match on your filter, then the first "row" is at index 0. Any changes you make will be reflected in the underlying datatable, and can be saved with the dataadapter's .Update method.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
hmm....ok...seems like your idea kind of works. When I update the row directly through the dataview, the datagrid that is bound to the dv is updated with the new information, but when I call the da.Update command it doesn't commit the changes to the database.

Here's my code:
Code:
 Call ChangeRowFilter(scannedMember.TDL, scannedMember.State)
            If dv.Count = 0 Then
                '   anyrow("MemberID") = scannedMember.TDL
                DsMembers.Members.Rows.Add(anyrow)
            Else
                With dv
                    .Item(0).Item("FirstName") = scannedMember.FirstName
                    .Item(0).Item("MiddleName") = scannedMember.MiddleName
                    .Item(0).Item("LastName") = scannedMember.LastName
                    .Item(0).Item("Address") = scannedMember.Address
                    .Item(0).Item("City") = scannedMember.City
                    .Item(0).Item("State") = scannedMember.State
                    .Item(0).Item("Zip") = scannedMember.Zip
                    .Item(0).Item("TDL") = scannedMember.TDL
                    .Item(0).Item("DOB") = scannedMember.DOB
                    .Item(0).Item("DateJoined") = scannedMember.DateJoined
                    .Item(0).Item("DateExpired") = scannedMember.DateExpired
                    If scannedMember.Barred <> Nothing Then
                        .Item(0).Item("Barred") = scannedMember.Barred
                    Else
                        .Item(0).Item("Barred") = "N"
                    End If
                End With
            End If
            If btnMode.Text = "Scan Mode" Then
                btnMode.PerformClick()
            End If
            Try
                lblName.Text = scannedMember.FirstName.ToString & " " & scannedMember.MiddleName.ToString & " " & scannedMember.LastName.ToString
                lblAddress.Text = scannedMember.Address
                lblCity.Text = scannedMember.City.ToString & ", " & scannedMember.State.ToString & " " & scannedMember.Zip.ToString
                lblDOB.Text = scannedMember.DOB.ToShortDateString
                lblStatus.ForeColor = System.Drawing.Color.Purple
                lblStatus.Text = "Member Added"
                odbdaMembers.Update(DsMembers)
                '      PrintDocument1.Print()
                If hostName.ToLower = fileServer.ToLower Then
                    NotifyClients.Main()
                Else
                    Call notifyServer()
                End If
            Catch db As Data.OleDb.OleDbException
                MsgBox("Connection to database has encountered a problem.")
            Catch pr As Printing.InvalidPrinterException
                MsgBox("An error occurred when attempting to print the membership form!")
            Catch ex As Exception
                MsgBox(ex.ToString)
                Exit Function
            End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top