T3hC13h's Profile User Rating: -----

Reputation: 65 Whiz
Group:
Active Members
Active Posts:
337 (0.17 per day)
Joined:
05-February 08
Profile Views:
5,423
Last Active:
User is offline Jan 13 2012 10:07 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Mitsubishi
Dream Kudos:
0

Latest Visitors

Icon   T3hC13h has not set their status

Posts I've Made

  1. In Topic: 'Pinger' Ping tool

    Posted 3 Jan 2012

    View PostToshNeox, on 30 December 2011 - 11:52 AM, said:

    ...Also, the cable is about 30 meters long so I can't afford to replace it and have to get it through the floor again xD


    Just buy a RJ-45 crimping tool and replacing the broken connector.
  2. In Topic: 'Pinger' Ping tool

    Posted 30 Dec 2011

    Why didn't you just buy a new cable?
  3. In Topic: Full implementation or properties?

    Posted 20 Dec 2011

    View PostRexGrammer, on 20 December 2011 - 12:23 PM, said:

    Thanks for all the feedback! :D

    Quote

    Also, the _varname thing makes me twitch.


    I started using it when I bought Re#er. It's because it prompts you to rename it, why I started using it.


    I understand this is a matter of taste/religion but I actually prefer the use of prefixing private fields wrapped in properties with an underscore because it prevents naming collisions with variables in method scopes.
  4. In Topic: Full implementation or properties?

    Posted 20 Dec 2011

    I caution you against creating properties (or any type of method) with side-effects. While you may not have any issues in some instances, it may come back to bite you as the code ages. But you should of course evaluate this on a case by case basis.

    As this is mostly a matter of readability and maintainability, first ask your self which is more readable.

    Player.IncreaseBalance(200)
    

    Or
    Player.Balance += 200
    


    Lets say you've opted for dedicated methods to access your fields. First off, you you've already run into an issue because you've declared GetName as an int instead of an string. Yes the compiler will catch the mistake but it illustrates the point that by opting against the language feature of auto/explicit properties you're opening yourself up to bugs as well as making yourself think about how your classes work more than you should.

    Side note: Its highly recommended to override ToString on most of your classes and your Player class is a prime candidate.
  5. In Topic: More than 1 SQLCommand statements 1 below other in c#

    Posted 12 Sep 2011

    I'm going to head you off before you get too far down this path of madness, don't prefix your variable names with their type, the IDE will tell you what they are. Just give your variables meaningful names within the context of the problem your trying to solve.

    What you're trying to do can be done many different ways but here are a few I came up with.

    In this method I've combined the two statements into one DB call, added a parameter to prevent SQL injection and wrapped the sqlconnection and datareader in using statements so I don't have to manually close them.
    using (var conn = new SqlConnection(@"Data Source=VAIBHAV-0EC092B\SQLEXPRESS;Initial Catalog=Navodayagiri;Integrated Security=True")) {
    	conn.Open();
    	var cmd = new SqlCommand("select Remaining_Dues from DuesMaster where Flat_No=@0;SELECT Name from HolderaNames where Flat_No=@0;", conn);
    	cmd.Parameters.AddWithValue("@0", txtflatno.Text.Trim());
    	using (var dr = cmd.ExecuteReader()) {
    		if (dr.HasRows) {
    			dr.Read();
    			txtoutstandingdues.Text = dr.GetString(0);
    			dr.NextResult();
    			dr.Read();
    			txtname.Text = dr.GetString(0);
    		}
    	}
    }
    


    In this method I'm making two calls to the DB but reuse the same Command object and connection.
                var conn = new SqlConnection(@"Data Source=VAIBHAV-0EC092B\SQLEXPRESS;Initial Catalog=Navodayagiri;Integrated Security=True");
                conn.Open();
    			cmd.Parameters.AddWithValue("@0", txtflatno.Text.Trim());
                var cmd = new SqlCommand("select Remaining_Dues from DuesMaster where Flat_No=@0;",conn);
                txtoutstandingdues.Text = cmd.ExecuteScalar().ToString();
                cmd.CommandText = "SELECT Name from HolderaNames where Flat_No=@0;";
                txtname.Text = cmd.ExecuteScalar().ToString();
                conn.Close();
    


    And my personal favorite is to use the amazing Simple.Data library.

    var db = Database.OpenConnection(@"Data Source=VAIBHAV-0EC092B\SQLEXPRESS;Initial Catalog=Navodayagiri;Integrated Security=True");
    var flatNo = txtflatno.Text.Trim();
    txtoutstandingdues.Text = db.DuesMaster.FindByFlat_No(flatNo).Remaining_Dues;
    txtname.Text = db.HolderaNames.FindByFlat_No(flatNo).Name;
    

My Information

Member Title:
D.I.C Regular
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
NY
Interests:
breaking things
Years Programming:
2
Programming Languages:
C#,VB.Net,SQL

Contact Information

E-mail:
Click here to e-mail me
AIM:
AIM  ndrewaa
Website URL:
Website URL  http://

Friends

Comments

Page 1 of 1
  1. Photo

    sondar311 Icon

    01 Mar 2010 - 08:58
    thanks for your help!
Page 1 of 1