Application help PLEASE... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Application help PLEASE...

quochaiquochai Posts: 6Member
I need to create a windows application that deletes records from a database that are old. This app doesnt have a GUI but should just do its tasks and close. I am brand new to C# and would love any feedback on how I should do this or any code suggestions.

Thanks.

Comments

  • weiccoweicco Posts: 950Member
    : I need to create a windows application that deletes records from a database that are old. This app doesnt have a GUI but should just do its tasks and close. I am brand new to C# and would love any feedback on how I should do this or any code suggestions.
    :
    : Thanks.
    :

    1. Create Windows Forms application
    2. Remove the form Visual Studio created from your project
    3. Take form creation code and Application.Run stuff out of Main-method
    4. Connect to database (in Main-method)
    5. Send sql command to database
    6. Disconnect database and you are done

    Parts 1-3 prevents any window from appearing. You could also create command line application but then you get that ugly black DOS box showing. In part 4-6 use xxxConnection and xxxCommand classes, where xxx is the name of the database (for example SqlConnection for SQL Server).

    Pretty simple thing, below 20 lines of code easily :)
  • quochaiquochai Posts: 6Member
    Hey Thanks alot,
    could you write me a sample of what the code would look like? I just dont see it being under 20 lines. This application needs to automatically delete old records and I should use it in my windows schedule tasks.
    Thanks.


    : : I need to create a windows application that deletes records from a database that are old. This app doesnt have a GUI but should just do its tasks and close. I am brand new to C# and would love any feedback on how I should do this or any code suggestions.
    : :
    : : Thanks.
    : :
    :
    : 1. Create Windows Forms application
    : 2. Remove the form Visual Studio created from your project
    : 3. Take form creation code and Application.Run stuff out of Main-method
    : 4. Connect to database (in Main-method)
    : 5. Send sql command to database
    : 6. Disconnect database and you are done
    :
    : Parts 1-3 prevents any window from appearing. You could also create command line application but then you get that ugly black DOS box showing. In part 4-6 use xxxConnection and xxxCommand classes, where xxx is the name of the database (for example SqlConnection for SQL Server).
    :
    : Pretty simple thing, below 20 lines of code easily :)
    :

  • weiccoweicco Posts: 950Member
    : Hey Thanks alot,
    : could you write me a sample of what the code would look like? I just dont see it being under 20 lines. This application needs to automatically delete old records and I should use it in my windows schedule tasks.
    : Thanks.
    :

    [code]
    static int Main(void)
    {
    SqlConnection conn = new SqlConnect(ion"connection string here");
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = conn;
    // Delete rows that are more than 10 days old
    cmd.CommandText = "DELETE FROM MyTable WHERE MyTimeStampField < DATEADD(day, 10 GETDATE())"
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    }
    [/code]

Sign In or Register to comment.