Assignment 3

In this assignment we are going to create tables in a database and perform some queries. We are not going to handle all kinds of SQL statements.

We are using a database system called MariaDB, a clone of MySQL.

The tables we will use are described below.

The input files we will use are described below. You can find links to them on the web site.


What to do

Write code to do the following in a Form application:

Your form should include:

You might need more Labels as well.

In the form Load event handler, do the following:

When a user types in a SQL command and clicks the Execute button, the string in the TextBox needs to be executed. In the button handler:

In the event that the user-supplied SQL command is not valid, we will have an error. You need to handle this.

If the user clicks the Clear button, delete the contents of the TextBox and the ListBox.

If the user clicks the Exit button, end the form application.


Other notes

As MariaDb and MySql are not Microsoft products, support for them are not built into C#. To use it, we need to download and install the appropriate files into the project (separately for different projects). To do this:

Also, to use the MySql library, we will need some using statements:

     using System.Data;
     using System.Data.SqlClient;
     using MySql.Data;
     using MySql.Data.MySqlClient;

To connect to your database, you need values for three keywords in the connection string: uid, pwd and database.

If you are in group 1, your string should be:

     "server=10.158.56.53;uid=csci473g01;pwd=wordpass01;database=csci473g01;"

For the other groups, the same pattern applies. For group M, use the string:

     "server=10.158.56.53;uid=csci473gM;pwd=wordpassM;database=csci473gM;"

replacing M by its value as 2 digits. Notice the user ID is the same as the database name.

You can find the group number to use on Blackboard as a column in the Gradebook.

Whenever you are going to open a connection, do so with a "using" block to ensure that the connection will be closed at the end of the block.

Pick a foreground color and a background color for your form, and also choose at least one font and font size. (There is no obligation to use the default.)

To make the output easier to read, skip a line in the ListBox between queries.

Some of the steps described above should be done using the ExecuteNonQuery method of the MySqlCommand class.

Although the GetSchema method can do other things as well, all we want is the list of names of tables.


Description of the input files

We have three input files.

Office.txt contains the information for OfficeTable. Each line in the file corresponds to one row in the table. The fields are separated by commas.

Room.txt contains the information for RoomTable. Each line in the file corresponds to one row in the table. The fields are separated by commas.

Class.txt contains the information for ClassTable. Each line in the file corresponds to one row in the table. The fields are separated by commas.

When you read the file, use ReadLine to read each line of data as a string. Now use the Split method of the String class to divide the original string into substrings. (Look for the MSDN page on the Split method and look at the example.) In some cases you will need to convert a string to an integer; you can use one of the static methods of the Convert class. You will then need to concatenate strings to create the SQL string for the Insert command.

As with Assignments 1 and 2, you should copy these files into the bin/debug subdirectory of whatever directory contains your Assignment 3 project.


Description of the tables

We have 3 tables.

OfficeTable has 2 columns:

RoomTable has 3 columns:

ClassTable has 6 columns:

Use the following names for columns in your tables: Teacher, Office, Room, Capacity, Smart, Class, Time, Days, Enrollment.


While the user might type various queries, here are a few to use in testing. You will need to rewrite them in SQL.

Who is teaching course 311-1?

Which classrooms are smart classrooms?

How many classrooms are smart?

Which classes meet on TTh?

What is Green's office number?