T3hC13h's Profile
Reputation: 65
Whiz
- Group:
- Active Members
- Active Posts:
- 337 (0.17 per day)
- Joined:
- 05-February 08
- Profile Views:
- 5,423
- Last Active:
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
-
CodingSup3rna... 
22 Sep 2011 - 11:59 -
Amrykid 
23 Aug 2011 - 09:50 -
no2pencil 
02 Jul 2011 - 21:31 -
leadfirelf 
28 Jun 2011 - 13:17 -
raziel_ 
15 Jun 2011 - 08:50
Posts I've Made
-
In Topic: 'Pinger' Ping tool
Posted 3 Jan 2012
-
In Topic: 'Pinger' Ping tool
Posted 30 Dec 2011
Why didn't you just buy a new cable? -
In Topic: Full implementation or properties?
Posted 20 Dec 2011
RexGrammer, on 20 December 2011 - 12:23 PM, said:Thanks for all the feedback!
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. -
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. -
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:
-
ndrewaa
- Website URL:
-
http://
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
sondar311
01 Mar 2010 - 08:58