C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Application help PLEASE... Posted by quochai on 8 Feb 2006 at 12:21 PM
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.
Report
Re: Application help PLEASE... Posted by weicco on 8 Feb 2006 at 10:41 PM
: 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 :)
Report
Re: Application help PLEASE... Posted by quochai on 9 Feb 2006 at 7:01 AM
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 :)
:

Report
Re: Application help PLEASE... Posted by weicco on 9 Feb 2006 at 11:53 AM
: 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.
:

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();
}





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.