• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 742
  • Last Modified:

Visual Studio - Using Databases

Below is the code from a practice routine right from the textbook. I am sure I entered the code exactly as they showed but I get errors which I have listed at the bottom. I need to understand and get this right because the problems at the end of the chapter refer back to this routine. Please advise.

Thank you!!

Robert

' Name:         Raye Industries Project
' Purpose:      Display the records stored in a database; display
'               records with last names matching one or more characters;
'               display the average pay rate
' Programmer:   <your name> on <current date>

Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'EmployeesDataSet.tblEmploy' table. You can move, or remove it, as needed.
        Me.TblEmployTableAdapter.Fill(Me.EmployeesDataSet.tblEmploy)

    End Sub

    Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        ' moves the record pointer to the previous record

        TblEmployBindingSource.MovePrevious()

    End Sub

    Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        ' moves the record pointer to the next record

        TblEmployBindingSource.MoveNext()

    End Sub

    Private Sub btnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFind.Click
        ' displays records whose last name begins with the user's entry

        Const strPROMPT As String = "Enter one or more characters in the last name. Or leave blank to retrieve all records."
        Dim strSearch As String

        ' get user input

        strSearch = InputBox(strPROMPT, "Find Last Name").ToUpper

        ' select the appropriate records
        Dim records = From employee In EmployeesDataSet.tblEmploy _

        Where employee.Last_Name.ToUpper Like strSearch & "*",  _
        Select employee

        ' display the records
        TblEmployBindingSource.DataSource = records

    End Sub

    Private Sub btnAverage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAverage.Click
        ' displays the average pay rate

        ' calculate average pay rate
        Dim avgRate = Aggregate employee In EmployeesDataSet.tblEmploy _
                    Select employee.Rate Into Average()

        ' display average pay rate
        MessageBox.Show("Average pay rate for all employees: " _
                        & avgRate.ToString("C2"), "Raye Industries", _
                        MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
End Class

Error      1      Name 'Where' is not declared.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      46      9      Raye Industries Project

Error      2      Method arguments must be enclosed in parentheses.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      46      15      Raye Industries Project

Error      3      Name 'employee' is not declared.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      46      15      Raye Industries Project

Error      4      Expression expected.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      47      9      Raye Industries Project
0
Robert Ehinger
Asked:
Robert Ehinger
  • 2
1 Solution
 
alb66Commented:
      ' select the appropriate records
        Dim records = From employee In EmployeesDataSet.tblEmploy _
                                                                                                                          <------ remove this empty line
        Where employee.Last_Name.ToUpper Like strSearch & "*",  _
        Select employee
0
 
dqmqCommented:
This statement is probably the source of all errors  It appears to be an assignment statement, but I can only guess how to fix it.


  ' select the appropriate records
        Dim records = From employee In EmployeesDataSet.tblEmploy _

        Where employee.Last_Name.ToUpper Like strSearch & "*",  _
        Select employee


Perhaps try this:
  ' select the appropriate records
        Dim records = "Select employee From employee In EmployeesDataSet.tblEmploy Where employee.Last_Name.ToUpper Like '" & strSearch & "*'"
0
 
Robert EhingerIT specialistAuthor Commented:
OK, I removed the blank line and now I have two different errors. I tried dqmq's suggestion but that didn't work. The errors I now have are -
Error      1      Keyword is not valid as an identifier.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      45      9      Raye Industries Project
Error      2      Name 'records' is not declared.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      48      45      Raye Industries Project


If I use dqmq's suggestion I get the following 3 errors -
Error      1      'Select Case' must end with a matching 'End Select'.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      45      9      Raye Industries Project
Error      2      Name 'employee' is not declared.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      45      16      Raye Industries Project
Error      3      Statements and labels are not valid between 'Select Case' and first 'Case'.      F:\CINS137\Course Technology\Programming\Clearly VB\Data Files\9781423902416_Data\Chap26\Raye Industries Solution\Raye Industries Project\frmMain.vb      48      9      Raye Industries Project
0
 
Robert EhingerIT specialistAuthor Commented:
I got it. Besides the blank line that need removed, I had a comma that didn't belong right after the "*". Thanks!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now