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
Robert EhingerIT specialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.