Debug Dataset error

I got this error:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

With the debug tricks from PaulStock, that helps!



Reformat/Re-align code in Visual Studio

Found a useful tip when I looking for StyleCop essay.

How to: Reformat your code in Visual Studio

In brief, do these:

  1. Select the code you want to re-format (CTRL + A if want to re-format whole file).
  2. Press CTRL + K
  3. Press CTRL + F
  4. Done.


If work in VB.Net, it will auto set TitleCase and align the code, however in C#, it only re-align the code, but this is the feature I like the most since C# code never align for you again if the alignment was out.


Reference: How to: Reformat your code in Visual Studio

Keyword: Alignment, align, code style

Add keyboard query shortcuts to your SQL Query Windows

You can add the frequently use s.procedure as your keyboard shortcut in your query analyzer(sql 2000) or sql server management studio.

For example, you always need sp_helptext to check existing s.proc in your database, you may type “sp_helptext myStoreProcedure” in your query screen, and hit “F5” to see the outcome.

Now you have faster way to do that, by attach sp_helptext to a keyboard shortcut,

  1. Go to “Tools -> Options”
  2. When Options screen pop up, go to “Environment -> Keyboard”.
  3. Key in “sp_helptext” in the keyboard shortcut you want, refer to image below, in this case is taking “CTRL + F1” shortcut.
  4. Click OK.
  5. Restart Query Analyzer/ SQL Server Management Studio to let the changes take effect.

How to use?

Highlighted the s.procedure you want to check, press “CTRL + F1”, this will call up sp_helptext shortcut that you set up in earlier steps, the content of the stored procedure will be shown immediately in Results pane.

Picture reference:

You can also add your own s.proc to keyboard shortcut, it never restrict to system s.procedure.

Keywords: Query shortcuts, keyboard shortcuts, Keyboard options, Environment settings, keyboard settings, Customize keyboard shortcuts.

Commond Prompt for Visual Studio .Net

If you install Visual Studio 2005, you would not face this problem, because the commond prompt and other tools already appear in your classical Windows Start Menu.

However if you install Visual Studio Express Edition, you would not get any shortcuts for those tools, let say you need the command prompt which support Visual Studio .Net, you need to type “cmd” in ‘Run’ dialog, and change the directory to .NetFramework folder.

Unfortunately I using Express edition in office, therefore I need to work around to get the ‘Visual Studio Command Prompt’. After compare with ‘real’ Visual Studio command prompt, below is my work around, the key is:

  1. Call a new console screen from batch file.
  2. Attach necessary path for .Net in new console screen, so you do not need to change to .Net directory when u need the command in .Net.

Please refer to your own .Net Framework version when doing this, example below is just for .Net version 2.0 .


  1. Create an empty batch file, insert line in # 2 into batch file, DO include double quote.
  2. cmd /K “path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727&&cls”
  3. Place the batch file in appropriate directory, create a shortcut for the batch file.
  4. Select Properties of the shortcut, change ‘Start in:‘ from current directory to ‘C:\(arbitrary directory)’
  5. Now double click the shortcut, Windows prompt up a clean cmd console screen which support .Net Framework command (since already setup in PATH).


Explaination for step # 2:

  • Command string after /K will be carry out and apply to new console process.
  • the ‘&&’ is the separator for seperated commands in same line, the line above consists two commands, first is append the path, second is clear the screen after append path.


Explanation for steps # 3 and # 4:

  • There are two ways to set the PROMPT in console window, the first way already show in steps 3 & 4, so you just put any startup directory you like in step 4.
  • The second way, you need to amend step 2 a bit, change it to below:

cmd /K “path=%path%;C:\WINDOWS\Microsoft.NET\Framework\


Ya, it is just add in another command for new console screen (Set the PROMPT=C:\Windows$G).


Keyword: Visual Studio Console Window, Tool, Tools, IDE, Command prompt

Display forward slash (’/’) in date using C#

Still remember my previous post ? Display forward slash (’/’) in date under VB6

I face the same issue in C#, however the solution this time is slightly different with solution in VB6.

//   First solution : surround the desired date seperator
//   ('/' in this case) with single quote.
string date = DateTime.Today.Date.ToString("dd'/'M'/'yyyy");

//   Second solution : same like solution in VB6,
//   except add '@' in front of the string.
string date = DateTime.Today.Date.ToString(@"dd\/MM\/yyyy");


Keyword: Date seperator, date format, date pattern, C#, .Net, forward slash

Display forward slash (‘/’) in date under VB6

When want to show forward slash (‘/’) in date, I use the code below:


However above code will return 31-01-2008, this is because forward slash “/” will replace by default separator in local PC if default date seperator is “-“.

To check your default date seperator, go to : Control Panel->Regional Settings->Customize->Date-> “Date seperator” in Short date format


You would not see the problem if your local PC date seperator is “/”.

In order to ensure system print the forward slash in date,use the code below:


The code will give 31/01/2008 no matter what is the date seperator.


Search Keyword: Date, slash, seperator