Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VISUAL BASIC VISUAL BASIC VISUAL BASIC So far I have created an application wher

ID: 3745461 • Letter: V

Question

VISUAL BASIC VISUAL BASIC VISUAL BASIC
So far I have created an application where a query executes against a Players table of a Baseball database. The table is displayed in DataGridView. Add a TextBox and Button allows the user to search for a specific player by last name. Here is the code I have for the last name button:

Dim lastNameQuery =
            From player In dbcontext.Players
            Where player.LastName.StartsWith(txtLastName.Text)
            Order By player.LastName, player.FirstName
            Select player

        'display results
        PlayerBindingSource.DataSource = lastNameQuery.ToList()
        PlayerBindingSource.MoveFirst() 'go to first result

Now I need help:

I need to allow the user to locate players with batting averages in a specific range. I added a minimumTextBox for the minimum batting average (0.000 by default) and a maximumTextBox for the maximum batting average (1.000 by default). I added a Button for executing a query that selects rows from the Players table in which the BattingAverage column is greater than or equal to the specified minimum value and less than or equal to the specified maximum value.

I cannot figure out the code to display the results based on the range the user puts in. Can anyone create the code for the batting average button, which brings up results from the table within range of the min and max bating average that the user enters?

Explanation / Answer

Hey,take the minimum value and max value as a number from text feild. If there is a column with name battingAverage in database then this should work.

Dim lastNameQuery =
            From player In dbcontext.Players
            Where player.LastName.StartsWith(txtLastName.Text) And player.batingAverage > txtMiinimumValue.Text And player.battingAverage < txtMinimumValue.Text
            Order By player.LastName, player.FirstName
            Select player

        'display results
        PlayerBindingSource.DataSource = lastNameQuery.ToList()
        PlayerBindingSource.MoveFirst() 'go to first result