Limited Offer Get 25% off — use code BESTW25
No AI No Plagiarism On-Time Delivery Free Revisions
Claim Now

Fourth GUI

After this lab, students will be able to:

  1. Use NuGet to install Visual Studio plugins from the Internet
  2. Identify and fix missing using directive errors
  3. Create a List collection that contains strings
  4. Integrate an SQLite database into Visual Studio
  5. Display the results of an SQL SELECT query into a ListBox in C#

Follow these instructions carefully to complete the assignment. If you have questions at any time, don’t hesitate to send me an e-mail or stop by my virtual office.

You’ll do this lab in a pair (or individually, if you can’t contact your pair).

WARNING: This project must be done in Visual Studio 2017 or 2019. 2015 won’t work.

Forking the base repository

The steps to fork the repository are the same as in FirstGUI, only with a different link: 

You can find the instructions for forking the repository

in FirstGUI. Make sure both people are in the team, if you’re working in a pair.

Exploring the XAML

Make sure you look at the XAML layout and see if you can understand what controls are included in the project and how they are laid out.

Installing NuGet packages

In order to link the project to a real SQLite database, we need to download a Visual Studio “plugin”. In order to do this, we need to use something called NuGet.

NuGet is a “package manager”. A package manager is used to help users install software that may contain multiple dependencies. A software dependency exists if a piece of software needs another piece of software in order to run.

As I said before, in Visual Studio, NuGet is the package manager. It handles the installation, uninstallation, and updating of Visual Studio plugins. These plugins add functionality to Visual Studio after installation. SQLite is one of these plugins.

To install SQLite, right click on the SQLiteIntegration solution in the Solution Explorer and go to Manage NuGet Packages for Solution…”

Click on the Browse tab and type System.Data.SQLite.Core

Make sure the project is selected in the right hand pane and click Install. Accept any license agreements and other installation windows. It may take a few minutes for it to finish installing.

Adding using references

I’ve included some source code that links the application to the database, but it’s not quite done. Your file still has some compile-time errors. Let’s fix those next.

Even though you’ve added the NuGet package, you still need to be able to use those classes in your code. You do this via the using statements at the top of pretty much all C# programs.

Find the error associated with DataTable. It’s after the comment that says “MARKER – Probably an error here” inside MainWindow.xaml.cs. With your keyboard cursor on the red underlined text, type Ctrl+. (or right click and choose “Quick Actions and Refactorings..”) From that menu, select using

System.Data;

This adds the classes inside that namespace to your code, so it can use the DataTable. You can see that is so at the top (the using System.Data; line should have been added)

You should be able to follow the same process for fixing SQLiteConnection and SQLiteDataAadapter. Do that now.

There’s still one more error…

Adding an Instance Variable

The playerList variable is supposed to be a List of strings, storing the results of our SQL query, but I haven’t added the declaration and initialization of the variable! playerList should be an instance variable, because it is accessed from multiple different methods.

This instance variable is probably slightly different from ones you’ve used before. We’re going to create a collection of strings. To do this, you’ll need to use the following declaration (and initialization) for the instance variable.

List<string> playerList = new List<string>();

Insert this code into MainWindow.xaml.cs now. Recall from Programming II that an instance variable should be outside of any method, but inside the class scope.

Note: Once inserted, this has the same error as DataTable earlier, since we’re using a “not-built-in” component of C#. Go ahead and fix it the same way.

Wait! So, what are those < and > signs, you may be asking? If you recall from Programming II, you’d typically declare and initialize an instance variable like so: DataType variableName = new DataType(); This is similar, but includes a concept called Generics. I’ll leave the specifics to Data Structures, but you can imagine that the line of code above creates an empty list (like an array) that will eventually store strings. If you put bool between the < and > sign, it would create a list of bools, if you put List inside there, it would create a List of Lists!

Once you have the instance variable declared and initialized, your code should be free of errors. Go ahead and run it now.

Making something different show up

You should see a comment that says MARKER: Making something different show up in your code. On the very next line, you should see string playerRow = $”row[0].ToString()”;

Answer the discussion questions in this section with an experimental mindset to see if you can figure out what that line is doing. If at any point in the series you start getting compile-time errors, spend a couple minutes trying to figure it out. Send me an e-mail if you can’t get it working.

Modifying the SQL query

So, hopefully you figured out that the row array stores the value in each of the rows that come back from executing the SQL query. row[0] corresponds to the first attribute in the SELECT clause, row[1] corresponds to the second attribute in the SELECT clause, and so on.

Play with this a little. What else can you display from the Batting table? If you want to practice the SQL query separate from C#, you can load the lahman database (on Blackboard) into sqliteonline – just like you do with the Chinook database.

As with the previous section, if you run into trouble, spend 10 or 15 minutes trying to fix it, then send me an e-mail.

The Final Steps

Now, you know enough to finish the assignment! Complete the following steps:

When a user clicks Submit, it should display

  • The player’s first and last name, the number of doubles in their career, and the number of triples in their career
  • You should be able to change the values in the TextBoxes and get the results below,
  • Make sure you match my text exactly.

Posting to Blackboard

Commit and push your project to GitHub. If you don’t remember how to push to GitHub, check the instructions in FirstGUI. Go into our Blackboard course under Assignments. Click the FourthGUI link. Type in your GitHub username(s) and a link to the repository in the “Comments” box. Congratulations on creating a WPF application that connects to a database!

The post Fourth GUI appeared first on My Assignment Online.

Plagiarism Free Assignment Help

Expert Help With This Assignment — On Your Terms

Native UK, USA & Australia writers Deadline from 3 hours 100% Plagiarism-Free — Turnitin included Unlimited free revisions Free to submit — compare quotes
Scroll to Top