Curtis Rutland's Profile User Rating: *****

Reputation: 4531 Guru
Active Posts:
8,032 (5.02 per day)
08-June 10
Profile Views:
Last Active:
User is online A minute ago
Viewing Board Index

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Your Car:
Dream Kudos:
Expert In:
C#, LINQ, Dynamics CRM 2011

Latest Visitors

Icon   Curtis Rutland has been promoted!

Posts I've Made

  1. In Topic: How should you approach exception handling for simple small programs?

    Posted 23 Oct 2014


    I'm thinking that, whatever the exception is, the bottom line is that I can't read the file. If I can't read the file there's only one logical behaviour I would want the program to do. I can still write the exact exception to a log file for later troubleshooting, but this seems to me like it would be a better approach.

    That's why exception handling in C# is flexible; you can be as precise or as generic as you need to be.

    Typically, what you want to do is handle known, expected exceptions explicitly if you can do something about it. For instance, if you're expecting user input to tell you where the file is, you might expect a FileNotFound exception, and you know what to do in that case (ask your user again for a proper path). But for exceptions you can't recover from, you would catch it with the most generic type, System.Exception. And you would print it to a log file, and exit your program (or whatever you need to do to return to a usable state).

    Typically, a logging framework will be of use here. Loggers like log4net can automatically print all useful information from an exception, like messages, inner exceptions, and stack traces. I highly suggest looking into log4net or a similar logging framework.

    But you're on the right track. Don't worry about every possible individual exception. Explicitly catch the ones you expect and can recover from, generically catch the rest.
  2. In Topic: SQLException: Error converting data type varchar to numeric.

    Posted 22 Oct 2014

    In my writeup, I show how to use AddWithValue, which is much simpler than having to set a data type on each parameter. AddWithValue infers the type of the parameter with the type of the data provided.
  3. In Topic: How to repeat execution of code using a counter?

    Posted 22 Oct 2014

    You seem to have i declared as a class-level variable. Tough to say what's going on without seeing what else could be modifying i's value.

    Put a breakpoint on the if(i <= roundMax) line. Inspect i's value at the time of the check. See what it's set at. That won't lie. If i is less than seven, the code inside the if block will not be called.

    Side note: you mention in one line that roundMax is a constant value. Why not make it explicitly so? Just add the const keyword in front of the type to make it an actual constant.
  4. In Topic: SQLException: Error converting data type varchar to numeric.

    Posted 22 Oct 2014

    There's a link in my signature about using parameterized queries. I highly suggest you read through it. It's not just about protecting against SQL injection; parameterized queries are much easier to read and use.

    However! There's another option as well: an ORM like Entity Framework. It's a bit heavy-weight for this sort of thing, but it will make this insert statement a lot more trivial.

    An ORM like Entity Framework will connect to your database, download the schema of the selected tables/views/stored procedures, then generate classes for you that have properties that match the table's columns. Strings for varchars, ints for ints, bools for bits, etc...

    To do an insert, all you have to do is make a new instance of the generated class, and pass it into a data context. The context will handle generating the SQL to send to the server all by itself.

    If you're interested, look up some Entity Framework tutorials. Other options are LINQ to SQL (not being actively developed), NHibernate (which is good but not a Microsoft first party tool), and others like it.
  5. In Topic: How to execute a service once a month

    Posted 22 Oct 2014

    If your people are set on this being a Windows Service, you can use something like a compact database or even just a text file to store the date of your next run.

    I wouldn't trust a program to have a slept thread for a month. Nor would I want to use any of the built-in ways to delay. A month is a long time. Instead, what I would do is have some form of a scheduling database. Every time your program does it's thing, it writes an entry for when the next run should be. Then it waits. You can set your tick resolution for hourly or daily or whatever. Each time it ticks, it checks to see if it's later than the next scheduled run. If it is, it performs the run, then adds a new row. If not, it goes back to waiting.

    However, if you're not set on this being a Windows Service, I will also put my vote in for using the Task Scheduler. I've got three or four programs being triggered daily by the Windows Task Scheduler, and it works just fine. There's plenty of robust options like running as soon as possible after a missed scheduled run, etc...that will really make this a viable option.

My Information

Member Title:
(╯□)╯︵ (~ .o.)~
30 years old
August 29, 1984
San Antonio
Forum Leader:
Full Name:
Curtis Rutland
Years Programming:
Programming Languages:
C# -- Forms, WPF, Silverlight, WCF

Contact Information

Click here to e-mail me
Website URL:
Website URL
Skype  insertAlias_bytes


  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    NewRandomUsername Icon

    06 Jun 2014 - 20:59
    Did you get my messages(emails) sir?
  2. Photo

    BenignDesign Icon

    03 May 2013 - 13:29
    I see you were staring at my profile. I also stare randomly at profiles. We have much in common. We should probably hook up sometime. Just sayin.
  3. Photo

    eric wallace Icon

    31 Jan 2013 - 02:53
    can you help for visual basic
  4. Photo

    no2pencil Icon

    06 Dec 2012 - 08:34
    It still isn't good enough.
  5. Photo

    ikram002p Icon

    27 Jun 2012 - 10:51
    "It Doesn't Work!" That's not good enough!
    It Still Doesn't Work!.
    I didnt undestand it ??
  6. Photo

    tlhIn`toq Icon

    18 Mar 2012 - 11:22
    Congrats on breaking 3000
  7. Photo

    Curtis Rutland Icon

    08 Sep 2011 - 14:13
    "Leveling up." I like that!
  8. Photo


    08 Sep 2011 - 13:55
    Yar ya see, i remember when yee wer purple!
    Anyways congrats! It's weird seeing people who've been one way so long "leveling up" :P.
  9. Photo

    Curtis Rutland Icon

    08 Sep 2011 - 12:59
  10. Photo

    Sergio Tapia Icon

    08 Sep 2011 - 12:29
    Congrats on becoming a mod. :D
  11. Photo

    Ace26 Icon

    15 Jun 2011 - 13:39
    Hi mate, interesting to see we are age mates. Nice work you do in the forums.
    Just dropped by to say hi, anyways.
  12. Photo

    RetardedGenius Icon

    20 Apr 2011 - 18:56
    Excellent C# tutorials, they've taught me a lot I didn't know. Please keep more of the good stuff coming! :D
  13. Photo

    Curtis Rutland Icon

    24 Mar 2011 - 14:55
    Yeah, felt like "professionalizing".
  14. Photo

    Dogstopper Icon

    23 Mar 2011 - 17:08
    Woah. Name switch! I took a double take...
  15. Photo

    CodingSup3rnatur@l-360 Icon

    01 Mar 2011 - 14:35
    No problem at all. Glad I could contribute :)
  • (2 Pages)
  • +
  • 1
  • 2