Tuesday, August 18, 2009
Removing Unwanted Text from Tab-delimited Files using Regex
Wednesday, August 05, 2009
Settings DataSet/TableAdapter Connection Strings at Runtime
The DataSet's TableAdapter generates strongly types classes in VS.NET, with properties to connection strings that are read-only at runtime, unless, of course, you choose the "User" scope. Follow these steps for changing the connection string upon application startup:
- Open up the Settings.settings file, whatever it might be named in your project. If it's not there, create one by a) adding a new Settings file to your project, b) adding a new (Connection string) setting, c) save it, d) then ensure that each DataSet's TableAdapter's Connection property references this Settings file's (Connection string) setting.
- Press the F7 key to view its code.
- Add the following code to the Settings() constructor:
this.SettingsLoaded += new System.Configuration.SettingsLoadedEventHandler(Settings_SettingsLoaded); - Add the following method to the Settings class:
private void Settings_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e) { try { Settings.Default["PrizeWinsConnectionString"] = "PUT YOUR CONNECTION STRING HERE!"; } catch (System.Exception err) { throw; } } - Save and recompile your project/solution.
Monday, May 18, 2009
Removing decimal places in VS.NET 2008's Crystal Reports
There are times where the business requires numbers with decimal places to have those decimal places removed if the decimal value is zero. For example, it's better to display 707 than 707.00, but if it's 707.55, it still stays at 707.55. Here's how you can tell Crystal Reports to NOT use decimal places in this case.
- Open up the Crystal Report.
- Right-click on the decimal value field, then click on Format Object.
- Select the Number tab.
- Choose Custom Style, then click on the Customize button.
- Click on the X*2 button next to the Decimals drop-down box.
- Change it from Crystal Syntax to Basic Syntax.
- Enter something akin to the following code:
If ({TABLE.DECIMALFIELD} - Round({TABLE.DECIMALFIELD}, 0)) = 0.0 Then formula = 0 Else formula = 1 End If Where 0 and 1 are the number of decimal places. - Click on the Save and Close button.
- Click on OK twice, then save the report.
Tuesday, March 31, 2009
SQL Server 2005's EXCEPT & INTERSECT Union-like Operators
SQL Server 2005's Ranking Functions
You can create columns that provide unique ranking/sorting capabilities. For example, ROW_NUMBER() (produces unique row numbers):
Thursday, March 26, 2009
Creating Pivoted Joins in SQL Server 2005
You can take a vertical result set and turn it into a horizontal one, like this:
The preceding query takes a count of how many licenses belong to which BMW models, and displays them horizontally. The output should be something like this:
If were were to utilize a simple select statement, it would look something like this:
Wednesday, March 25, 2009
Random Data Sampling Queries in SQL Server 2005
The following query will return a random sampling of data:
New Join Types in SQL Server 2005
CROSS APPLY (equivalent to an inner join):
OUTER APPLY (equivalent to a left join):
Note that any object with no parameter or column will not have an any records in the syscolumns table (eg, SPROCs with no parameters).
Using Common Table Expressions in SQL Server 2005
Pretty cool stuff:
Results from my DB:
Tuesday, March 24, 2009
ASP.NET MVC - Validation of viewstate MAC failed.
Yup, View State is not supported in MVC, so beware of this. If you try to use a control that relies on it, you'll get the following error:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure thatconfiguration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Note that you can still use ViewState with ASPX/Web Forms as Views in MVC, but that violates the MVC pattern.