Simple C# Database Application

image

Basically, it prompts for a GITI ID, user enters an assignment number from the Education module, and it calls the database server and asks for the class code and the assignment name. Nothing special yet. I’m using the MySQL Connector for ADO.NET. It’s kind of lame, but is my first step towards a version of GITI that doesn’t require a web browser. This version talks directly to SQL, and its designed for an end-user, but my vision is to create a console-based server that will handle authenticating users and things like that, handling the interaction with the database itself. Ideally, the Windows Application will then talk to that server and perform its actions, while also maintaining a local cache of information.

In PHP, GITI’s native language, what I did looks something like this:

//get user input for $assID from form
$sql = "SELECT Code, Assignment FROM `homework` WHERE `ID`=’$assID’";
$sql_result = mysql_query($sql, $connection);
$row = mysql_fetch_array($sql_result);
echo $row["Code"];
echo " : ";
echo $row["Assignment"];

 

In C# it looks a little more like this:

string assID = tIn.ReadLine();
string selectStatement = "SELECT Assignment,Code FROM `homework` WHERE `ID`='" + assID+"'";
MySqlCommand selectCommand = new MySqlCommand(selectStatement, connection);
connection.Open();
MySqlDataReader custReader = selectCommand.ExecuteReader();
if (custReader.Read())
{
string ClassCode = custReader["Code"].ToString();
string AssignmentName = custReader["Assignment"].ToString();
tOut.WriteLine(ClassCode+" : "+AssignmentName);
}
connection.Close();
Console.Beep();

 

Both are very simple. In both examples, the connection properties for the server were set before the lines of code shown. C# is more manageable for doing this type of work once the "data assisting" features of Visual Studio 2008 are ignored. I love C# so far, but I am quickly learning that I can learn to love Visual C++ as well, there isn’t a lot different between the languages (why should there be, they both convert back to .NET Assembly). My frustration that I developed with C++ resulted from not ever being able to find documentation that I need about available "classes", and when I did find the classes I needed, they required additional classes to make them work. An absolutely endless cycle. For C#, there are a lot of built in classes for most common functions, and the documentation is plentiful (not the mention Visual Studio’s ability to read and define constructs in the classes as I get to them, providing me with instant ability to use functions). 

I still have to pick what language I want to take an advanced course in (for my Computer Programming degrees).