Hello...

I'm having a real hard time with displaying the proper data in Project Summary. First off, I am using an Access database to bring in the data. Total hours are being calculated correctly. Rates are as well. I tested using a messagebox to make sure the rates are being grabbed from the database correctly. However, now to get the total cost to multiply the individual rates by the individual hours is where I'm having the problem.
So to sum it all up, ALL I want to be able to do is multiply data from one table with data from another table. TWO separate select string statements. What am I doing wrong?!
Below I pasted the code I have so far and the directions in the assignment specs for this particular button. I highlighted the problem areas. If any one has any suggestions, they'd be greatly appreciated!

Thanks in advance...

[B]Project Summary[/B](button) – This button should display the total dollars and total hours expended on the currently selected project.   If the user clicks this button before a current project has been successfully selected, display an error message box and exit the sub. 
In order to produce the total hours and dollars, your logic will have to search the database tables billing and employee to look for charges to the current project the user has entered.
To compute dollars for that charge use, pay rate * hours charged.

My Code:

Private Sub btnSummary_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSummary.Click

        Dim targetid As String
        Dim selectstring As String
        Dim selectstring2 As String
        Dim dummy As Integer
        Dim amount As String = ""
        Dim totalHours As Double = 0
        Dim totalCost As Double = 0
        Dim Hours As Double = 0
        Dim Rate As Double = 0

        If Not Integer.TryParse(txtPID.Text.Trim, dummy)
Then
            MessageBox.Show("member id must be integer")
            txtPID.Focus()
            txtPID.SelectAll()
            Exit Sub
        End If
        targetid = txtPID.Text.Trim

        'select string statements

        selectstring = "select * from billing where
bill_projid ='" & _
                        targetid & "'"
        selectstring2 = "select * from employee,billing
where employee.emp_id = billing.bill_empid" & _
                        " and billing.bill_projid ='" &
targetid & "'"



        MessageBox.Show(selectstring)
        MessageBox.Show(selectstring2)

        'Fill
        projectadapter = New
OleDb.OleDbDataAdapter(selectstring, connectionstring)
        employeeadapter = New
OleDb.OleDbDataAdapter(selectstring2, connectionstring)

        emptable = New DataTable
        employeeadapter.Fill(emptable)

        projtable = New DataTable
        projectadapter.Fill(projtable)

        If projtable.Rows.Count = 0 Then
            lblDisplay.Text = "You have not yet loaded a
project."
            Exit Sub
        End If

        If emptable.Rows.Count = 0 Then
            lblDisplay.Text = "You have not yet loaded a
project."
            Exit Sub
        End If

        'for projtable
        For ndx = 0 To projtable.Rows.Count - 1

            totalHours +=
CDbl(projtable.Rows(ndx).Item("bill_hours").ToString)
            Hours =
CDbl(projtable.Rows(ndx).Item("bill_hours").ToString)
            'MessageBox.Show(CStr(Hours))<<-- each hour shows up correctly
        Next


        'for emptable
        For indx = 0 To emptable.Rows.Count - 1

            Rate =
CDbl(emptable.Rows(indx).Item("emp_payrate").ToString)
            'MessageBox.Show(CStr(Rate))<<-- each rate shows
up correctly
        Next


        total += Rate * Hours <<-- Always comes up as 80 (40
* 2)
        MessageBox.Show(CStr(Rate))
        MessageBox.Show(CStr(Hours))
        MessageBox.Show(CStr(total))

        totalCost = total

        lblDisplay.Text = "Total Hours to date: " &
totalHours.ToString & Environment.NewLine _
                        & "Total Cost to date: $" &
totalCost.ToString & Environment.NewLine


End Sub

Recommended Answers

All 2 Replies

Show us tables schema (structure of both these tables.)

Found out what the problem was. I was actually over-thinking A LOT. Turns out, it was just a simple database load from the class in the application that I needed to tweak. The Summary button didn't even need any database code.
Thanks though for responding!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.