Created
January 27, 2013 23:28
Revisions
-
NikkiBuck created this gist
Jan 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ public static int CountBirds(string baseBirds = "*", string baseBirder = "*", string baseRegion = "*", string baseDate = "*") { SqlCommand selectCommand; string sql = "SELECT SUM(BirdCount.Counted) FROM Bird INNER JOIN BirdCount ON Bird.BirdID = BirdCount.BirdID " + "INNER JOIN Birder ON BirdCount.BirderID = Birder.BirderID INNER JOIN Region ON BirdCount.RegionID = Region.RegionID " + "where BirdCount.BirdID ='" + baseBirds + "' AND BirdCount.BirderID = '" + baseBirder + "' AND BirdCount.RegionID = '" + baseRegion + "' AND BirdCount.CountDate = '" + baseDate + "'"; if (baseBirds == "*") { sql.Replace("BirdCount.BirdID ='" + baseBirds + "' AND", String.Empty); } if (baseBirder == "*") { sql.Replace("BirdCount.BirderID = '" + baseBirder + "' AND", String.Empty); } if (baseRegion == "*") { sql.Replace("BirdCount.RegionID = '" + baseRegion + "' AND", String.Empty); } if (baseDate == "*") { sql.Replace("BirdCount.CountDate = '" + baseDate + "'", String.Empty); } if (baseBirds == "*" && baseBirder == "*" && baseRegion == "*" && baseDate == "*") { sql = "SELECT SUM(BirdCount.Counted) FROM Bird INNER JOIN BirdCount ON Bird.BirdID = BirdCount.BirdID " + "INNER JOIN Birder ON BirdCount.BirderID = Birder.BirderID INNER JOIN Region ON BirdCount.RegionID = Region.RegionID "; } selectCommand = new SqlCommand(sql, new SqlConnection(connectingString)); try { selectCommand.Connection.Open(); return Convert.ToInt32(selectCommand.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { selectCommand.Connection.Close(); } }