Results 1 to 4 of 4

Thread: Logic Error or something else wrong?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2010
    Location
    Lake Gaston, NC
    Posts
    453

    Logic Error or something else wrong?

    using VB2010.

    In the code below, if the NumSalesFound is greater than 0, the Customer file is updated correctly.
    But, if the NumSalesFound is 0, the Customer file is not updated at all.

    What am I doing wrong?



    Problem Code:
    1. Private Sub UpdateCustFileWithNewLastSaleInfo(ByRef NumSalesFound As Integer, ByRef HoldCustNum As Integer)
    2.         Try
    3.             Dim MyConnectionString As String = "Data Source=" & ModPrimaryServer _
    4.                            & "\SqlExpress; Database=OlaDatabase; User Id=olaa; Password=tomcat;"
    5.  
    6.             Me.CustomersTableTableAdapter1.Connection.ConnectionString = MyConnectionString
    7.             Me.CustomersTableTableAdapter1.Fill(Me.DeiDatabaseDataSet23.CustomersTable)
    8.  
    9.             Dim CustFileIndex As Integer = Me.CustomersTableBindingSource1.Find("CCustomerNum", HoldCustNum)
    10.             If CustFileIndex > -1 Then
    11.                 Me.CustomersTableBindingSource1.Position = CustFileIndex
    12.  
    13.                 If Integer.Parse(txtCNumVehsPurchased.Text) > 0 Then
    14.                     txtCNumVehsPurchased.Text = ((Integer.Parse(txtCNumVehsPurchased.Text)) - 1).ToString
    15.                 End If
    16.  
    17.                 If NumSalesFound > 0 Then    ' NumSalesFound = the num of other Sales for this Cust(if any)
    18.                     txtCLastSaleStkNum.Text = txtStkNum.Text
    19.                     txtCLastSaleDate.Text = DateValue(txtVehSaleDte.Value)
    20.                     dtpCLastSaleDte.Value = DateValue(txtVehSaleDte.Value)
    21.                     txtCLastSaleFinLse.Text = ComboFinLse.Text
    22.                 Else
    23.                     txtCLastSaleStkNum.Text = ""
    24.                     txtCLastSaleDate.Text = ""
    25.                     dtpCLastSaleDte.Value = #2/2/2222#
    26.                     txtCLastSaleFinLse.Text = ""
    27.                 End If
    28.  
    29.                 Me.CustomersTableBindingSource1.EndEdit()
    30.                 Me.CustomersTableTableAdapter1.Update(DeiDatabaseDataSet23.CustomersTable)
    31.             End If
    32.  
    33.         Catch ex As Exception
    34.             Beep()
    35.             MsgBox("Error  " & ex.Message)            
    36.         End Try
    37.     End Sub

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Logic Error or something else wrong?

    the Customer file is updated correctly
    You really should know by now that those types of vague statements are not very help. What's not correct. What's happening or not happening?

    That being said, I would put a break point a line 17 and check the value of NumSalesFound.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2010
    Location
    Lake Gaston, NC
    Posts
    453

    Re: Logic Error or something else wrong?

    Thanks for the response. I have put a break point in the code; and the logic for both NumSalesFound > 0 and NumSalesFound = 0 are both executed correctly. The problem is that when the NumSalesFound = 0, the fields are not being changed to blank in the database; but remain unchanged to their previous values.

    However, when the NumSalesFound > 0, the fields in the database are being changed to the values in my code properly.

    And you are right, I really should know by now, and that is why I'm embarrassed to even have to ask this question!
    Last edited by DexterRose; Jan 12th, 2015 at 07:46 PM.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Logic Error or something else wrong?

    I'm guessing that the textboxes are bound to customerstablebindingsource1. Have you put a break point inside the "else" to make sure it is entering there. Say line 23.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width