PDA

View Full Version : VB.Net help (updating database)


Draft Dodger
02-23-2005, 01:28 PM
ok, I just can't wrap my brain around this - last year I created a program / database to help simplify a lot of my facepack work. At that point, all I was doing was reading from the database (not modifying) and it worked fine. This year I've done a lot of revamping, and one of the things I'm trying to do is be able to update the database...and it's not working. I make a change in the program, but there never seems to register any changes (I added a little debug routing to show if the dataset has been changed before updating, and it invariably says no...even though I've changed numerous fields).

relevant code:
(on frm_Load)

'-------------Fills Data Set using Data Adapter-------------
Dim pintRecords As Integer
pintRecords = odbaMLBdb.Fill(DsMLBds1)

'--------------Bindings to follow -----------------------------
Dim pbndTemp As Binding
Dim pdtTeams As DataTable

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldID")
txtID.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldTeam")
txtTeam.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldFirstName")
txtFirstName.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldLastName")
txtLastName.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fld40")
txt40.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldNRI")
txtNRI.DataBindings.Add(pbndTemp)

pbndTemp = New Binding("Text", DsMLBds1, "tblMLB.fldProspect")
txtProspect.DataBindings.Add(pbndTemp)


and then I have an update button which is linked to the following subroutine:
(including the debug)


Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Dim pdsModifiedRows As DataSet
pdsModifiedRows = DsMLBds1.GetChanges(DataRowState.Modified)

lblDebug.Visible = True
If DsMLBds1.HasChanges() Then
lblDebug.Text = "YES"
Else
lblDebug.Text = "NO"
End If

If Not pdsModifiedRows Is Nothing Then
odbaMLBdb.Update(pdsModifiedRows)
End If

DsMLBds1.AcceptChanges()


the data adapter update odbaMLBdb.Update(pdsModifiedRows) never happens because it never sees any changes made.

I know the loading of the dataset works fine, I just can't seem to get it to recognize that there's been a change (or do I need to do something else to designate change besides typing into the relevant text box?). It seems I'm just missing something obvious here...

dacman
02-23-2005, 01:44 PM
If Not pdsModifiedRows Is Nothing Then
odbaMLBdb.Update(pdsModifiedRows)
End If


This is passing the doesn't look right test with me.

Draft Dodger
02-23-2005, 07:48 PM
taking another swing...