Database abstraction class in C# Here is the link to the revised version of this code:
Database abstraction class in C# (version 2)

I am new to C# and have coded a database abstraction class that I would like to get comments on.  It uses prepared SQL statements.  I would like this to not get distracted with prepared statements versus non-prepared statements discussion; please just review the code assuming prepared statements are appropriate for this class.

class DatabaseAccess
{
    private SqlCommand alreadyDownloadedCommand;
    private SqlCommand markedDownloadedCommand;

    public DatabaseAccess()
    {
        SqlConnection myConnection = new SqlConnection("user id=username;" +
                                   "password=password;server=serverurl;" +
                                   "Trusted_Connection=yes;" +
                                   "database=database; " +
                                   "connection timeout=30");

        myConnection.Open();
        alreadyDownloadedCommand = getAlreadyDownloadedCommand(myConnection);
        markedDownloadedCommand = getMarkedDownloadedCommand(myConnection);
    }

    private SqlCommand getMarkedDownloadedCommand(SqlConnection connection)
    {
        const string markDownloadedInsert =
        @"insert into dbo.InspectionsDownloaded(FileName)
          values (@FileName)
        ";
        SqlCommand command = new SqlCommand(null, connection);
        command.CommandText = markDownloadedInsert;
        command.Parameters.Add(new SqlParameter("@FileName", System.Data.SqlDbType.Text, 80));

        return command;
    }
    private SqlCommand getAlreadyDownloadedCommand(SqlConnection connection)
    {
        const string alreadyDownloadedQuery =
        @"select count(*) as numDownloaded
            from dbo.InspectionsDownloaded id
           where id.FileName = @FileName
        ";
        SqlCommand command = new SqlCommand(null, connection);
        command.CommandText = alreadyDownloadedQuery;
        command.Parameters.Add(new SqlParameter("@FileName", System.Data.SqlDbType.Text, 80));

        return command;
    }
    public Boolean AlreadyDownloaded(String filename)
    {
        Int32 rowCount;
        alreadyDownloadedCommand.Parameters[0].Value = filename;
        rowCount = (Int32)alreadyDownloadedCommand.ExecuteScalar();
        return (rowCount != 0);
    }
    public void MarkDownloaded(String filename)
    {
        markedDownloadedCommand.Parameters[0].Value = filename;
        markedDownloadedCommand.ExecuteNonQuery();
    }
}
I am new to C# and have coded a database abstraction class that I
  would like to get comments on.  It uses prepared SQL statements.


No, it doesn't. If you want it to use prepared statements then you have to call Prepare() on the SqlCommand instances.

Whether you really want actual prepared statements or whether you just want to leave escaping to the library is, as you say, up to you.




class DatabaseAccess
{
    private SqlCommand alreadyDownloadedCommand;
    private SqlCommand markedDownloadedCommand;



Both SqlCommand and SqlConnection are IDisposable. Best practices would require you to make DatabaseAccess implement IDisposable by disposing of all three.




        SqlConnection myConnection = new SqlConnection("user id=username;" +
                                   "password=password;server=serverurl;" +
                                   "Trusted_Connection=yes;" +
                                   "database=database; " +
                                   "connection timeout=30");



If this is for a throwaway project, hard-coding the connection string like that is acceptable. If it's for a "serious" project then you should really get the connection string from App.config with System.Configuration.ConfigurationManager.ConnectionStrings. That has the benefit of allowing you to have dev and prod configurations, as well as to handle server migrations, password cycling, etc. without recompiling.




        SqlCommand command = new SqlCommand(null, connection);
        command.CommandText = markDownloadedInsert;



Why not this?

     SqlCommand command = new SqlCommand(markDownloadedInsert, connection);





        command.Parameters.Add(new SqlParameter("@FileName", System.Data.SqlDbType.Text, 80));



...


    public void MarkDownloaded(String filename)
    {
        markedDownloadedCommand.Parameters[0].Value = filename;



If filename is longer than 80 characters, it will be silently truncated. I would think it advisable to check the length and throw an ArgumentOutOfRangeException if it's too long. Similarly in the other method.




    public Boolean AlreadyDownloaded(String filename)
    {
        Int32 rowCount;



Finally, some debatable points of style. I think it's quite unusual to use Boolean, String, Int32 instead of the aliases bool, string, int. And it's fairly conventional that a method (or property) which tests a condition and returns a bool should have a name beginning Is: here IsAlreadyDownloaded.