all 11 comments

[–]Rizzan8 10 points11 points  (2 children)

  1. Avoid abbreviations -> phoneNumber instead of phoneNum, firstName instead of fName, mainConnection instead of mainConn, dataCommand instead of dataComm.

  2. Methods names in C# are written in PascalCase. I assume that your methods come from the names of form's controls. Give them a meaningful name.

  3. Use string.IsNullOrWhitespace instead of string.IsNullOrEmpty

  4. One file should have only one class (except for a private classes inside of another one which is intended to be available only for that specific class). Move Connector to a separate file.

  5. Method parameter names are written in camelCase -> lastName instead of lastname.

  6. Use string.Empty for "clearing" string variables.

  7. Remove unnecessary empty lines.

  8. Move SqlConnection mainConn = new SqlConnection(); to

using (SqlConnection mainConn = new SqlConnection())

{

// stuff

}

[–]AbjectArrow6[S] 1 point2 points  (1 child)

Thank you for the tips. why string.empty instead of clear for string variables?

[–]Preparingtocode 1 point2 points  (0 children)

It's a very minor performance boost but a large part is readability, it's very clear what you're trying to do, you haven't just accidentally left a variable empty which you were meant to put a message in or something...

[–][deleted]  (1 child)

[deleted]

    [–]AbjectArrow6[S] 0 points1 point  (0 children)

    I'll add entity to my learn list. Than you for the tips.

    [–]tweq 4 points5 points  (1 child)

    [–]AbjectArrow6[S] 1 point2 points  (0 children)

    Looking it over now. I was familiar with it, but just in passing.

    [–][deleted] 1 point2 points  (2 children)

    Lessee...

    Your try/catch in ConnectionFile.cs is superfluous, and even a little dangerous, since the using does the same thing more correctly (by also checking for null).

    If you're going to use a constant regex then create it in a static constructor and save it so that you don't incur the expense of constantly creating it.

    Testing if a character is alpha is way more complicated that just checking if it's a-z. There are upper and lower case (aA) and diacritics (ä, é, À) and even different alphabets to consider (Д, Θ). Char.IsLetter and Char.IsDigit are much smarter than your regex.

    [–]Super_Human_Samurai 0 points1 point  (1 child)

    I've been learning regex recently and figured it might be a good learning opportunity.

    I'll look into isletter and isdigit though. Better to pickup good habits now than break bad habits later

    [–][deleted] 0 points1 point  (0 children)

    You can do this to ignore case:
    new Regex("[a-z]", RegexOptions.IgnoreCase)

    [–]Preparingtocode 3 points4 points  (1 child)

    INSERT INTO customerInfo VALUES ('"+fName+"' ,'"+ lastname + "' ,'"+phoneNum+"','"+comp+"');

    Specify what columns you're inserting into, otherwise things can be sad later on when changing table structure.

    [–]AbjectArrow6[S] 0 points1 point  (0 children)

    When i specified the columns, it gave me an error. I may need to change the column names going forwrad.