Allow Only Numbers In A String – C#

Often you may have user input that needs to only be numbers, and the input doesn’t allow characters.  There is javascript that you can put on the front end to limit what keystrokes can be made in an input field; however, there are still ways around it.  Here’s a good filter method that you can…

1

Difference between two Dates

Here’s some useful code if you need to know how much time has elapsed between two days.         DateTime oldDate = new DateTime(2005, 7, 31);         DateTime newDate = DateTime.Now;           // Difference in days, hours, and minutes.         TimeSpan timeSpan = newDate – oldDate;           // determine how many days are in…

0

Regular Expression Library

Regular Expressions.  Joy oh Joy.  Here’s a great site to help ease the pain in writing one: Regular Expression Library.  They have over a thousand indexed expressions and it even has an online tool to help you test expressions: http://www.regexlib.com/RETester.aspx I used it to help me find a good expression for validating email addresses.  Check…

0

Use an Image in a HyperLinkColumn

I’ve seen a lot of posts on boards of people inquiring how to utilize an image in a hyperlinkcolumn.  I found those posts, because I was trying to do the same thing.  In my codebehind, I had some custom things going on for the link, and really didn’t feel like comprimising any of that by…

0

Formatting Strings in a DataGrid

In my opinion, one of the coolest .net controls is the DataGrid.  There is sooo much you can do with this puppy.  One of the things I like most about it is how you can choose to control or not control how data is rendered.  Which brings me to the topic of this post, how…

0

Determine how many records are in a DataSet

To determine how many records are in a dataset, you can use the Count method of the Rows in a table (last line in code).         // New DataSet         DataSet dbSet = new DataSet();           // Populate DataSet with data         dbAdapt.Fill(dbSet, "issueReport");           // Determine how many records we have        …

0

Date and Time in a SQL Statement (DateTime)

To get the date and time for a datetime value in SQL Server, use the GetDate method.  It will return the current system date and time in the SQL Server standard internal format for datetime values. This is a pretty useful function if you need to know the date/time in a select statement or a…

0

Close Registry Keys After Use

To open a windows registry key using C#, the code would look something like this: RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\TWC\\Applications", true); The RegistryKey object has lots of methods on it to CreateSubKey, DeleteSubKey, SetValue, DeleteValue, etc. Once you are done with the registry key, you MUST close the registry key by calling the Close() method. If…

0

How to debug JavaScript in Visual Studio

Follow these 2 simple steps and you will be debugging JavaScript with ease. 1.    Clear the “disable script debugging” checkbox in Internet Explorer’s advanced properties. 2.    Add the keyword “debugger” somewhere within your JavaScript. When you run the web page from Visual Studio in debugging mode, viola–when it hits the “debugger” statement, the Visual Studio…

0

How to swap two strings

using System; class SwappinStrings {     static void SwapStrings(ref string s1, ref string s2)     // The string parameter x is passed by reference.     // Any changes on parameters will affect the original variables.     {         string temp = s1;         s1 = s2;         s2 = temp;         Console.WriteLine("Inside the method: {0},…

0