#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Location
    USA
    Posts
    313
    Rep Power
    18

    Update Database in ADO.NET when using code not controls


    Below is some code that I guess is wrong. I can update the database on an edit but on an AddNew I am able to update the dataset but not the Database. What am I missing or how would I do this.
    PHP Code:
       Private Sub UpdateRecord()
            Try
                
    Dim selectNum As Integer

                
    If bAddNew True Then
                    Dim dr 
    As DataRow
                    dr 
    dsBidder.Tables("Bidder" ) .NewRow

                    dr
    .Item("BidderNumber" )  = txtBidderNumber.Text
                    dr
    .Item("Name" )  = txtName.Text
                    dr
    .Item("Address" )  = txtAddress.Text
                    dr
    .Item("City" )  = txtCity.Text
                    dr
    .Item("State" )  = cboState.Text
                    dr
    .Item("Zip" )  = txtZip.Text
                    dr
    .Item("Phone" )  = txtPhone.Text

                    dsBidder
    .Tables("Bidder" ) .Rows.Add(dr)

                    
    dsBidder.Tables("Bidder" ).AcceptChanges()

                    
    daBidder.Update(dsBidder.Tables("Bidder" ))

                    
    selectNum dsBidder.Tables("Bidder" ) .Rows.Count 1

                    MessageBox
    .Show(selectNum vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("BidderNumber" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("Name" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("Address" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("City" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("State" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("Zip" ) & vbCrLf _
                    Me
    .dsBidder.Tables("Bidder" ).Rows(selectNum).Item("Phone" ))

                    
    bAddNew False
                
    Else
                    
    'This updates fine on an edit
                    selectNum = dsBidder.Tables("Bidder" ) .Rows.Count - 1
                    MessageBox.Show(selectNum)

                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("BidderNumber" )  = txtBidderNumber.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("Name" )  = txtName.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("Address" )  = txtAddress.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("City" )  = txtCity.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("State" )  = cboState.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("Zip" )  = txtZip.Text
                    Me.dsBidder.Tables("Bidder" ) .Rows(selectNum).Item("Phone" )  = txtPhone.Text

                    daBidder.Update(dsBidder.Tables("Bidder" ) )

                End If

            Catch _ex As Exception
                Dim myError As String

                myError = "FormName: " & Me.ActiveForm.Name.ToString & _
                           vbCrLf & vbCrLf & "Error Message: " & _ex.Message & _
                           vbCrLf & vbCrLf & "Error Type: " & _ex.GetType.ToString & _
                           vbCrLf & vbCrLf & "Error Source: " & _ex.Source.ToString & _
                           vbCrLf & vbCrLf & "Error Stacktrace:" & _ex.StackTrace.ToString

                '
    This saves the error to a file so I can look at it later.
                
    ReportErrors(myError)

                
    MessageBox.Show(myError)

            
    Finally
                Beep
    ()   ' Beep after error processing.
            End Try

        End Sub 
    Last edited by iamtgo3; March 21st, 2003 at 12:13 PM.

IMN logo majestic logo threadwatch logo seochat tools logo