Posts

Showing posts from December, 2015

Set a value when the column is null

Set a value when the column is null In sql server 2008 there are two functions to replace  NULL  values with another values 1. ISNULL  function required two parameters: the value to check and the replacement for null values ISNULL(value,replacement) 2.COALESCE  function works a bit different  COALESCE  will take any number of parameters and return the first non-NULL value , I prefer COALESCE over ISNULL 'cause meets ANSI standarts, while ISNULL does not. COALESCE(value1,value1,value3, valueN,replacement) Solution 1: SELECT Name , DOB , ( CASE WHEN Address1 IS NULL THEN 'NA' ELSE Address1 END ) AS Address1 , ( CASE WHEN Address2 IS NULL THEN 'NA' ELSE Address2 END ) AS Address2 , ... FROM Users Solution 2: Use  isnull : SELECT Name , DOB , isnull ( Address1 , 'NA' ) as [ Address1 ], isnull ( Address2 , 'NA' ) as [ Address2 ], isnull ( City , 'NA' ) as...

C# : Check value stored inside string object is decimal or not

Use the Decimal.TryParse function. decimal value ; if ( Decimal . TryParse ( strOrderId , out value )) // It's a decimal else // No it's not. You can use Decimal.TryParse to check if the value can be converted to a Decimal type. You could also use Double.TryParse instead if you assign the result to a variable of type Double. MSDN example: string value = "1,643.57" ; decimal number ; if ( Decimal . TryParse ( value , out number )) Console . WriteLine ( number ); else Console . WriteLine ( "Unable to parse '{0}'." , value ); use  Decimal.TryParse   to check if the string entered is decimal or not.   decimal d ; if ( decimal . TryParse ( textBox1 . Text , out d )) { //valid } else { //invalid MessageBox . Show ( "Please enter a valid number" ); return ;   }  

How to bind dropdownlist inside gridview edit template

Image
Overview:   This article explains how to bind drop down list control which is placed inside Asp.net   Gridview  control under Edit Template. .i.e Gridview edit template dropdownlist bind. Also using  DataRowView  we able to get and set gridview edit template drop-down list value. On ".aspx" Page: Add gridview on design page like: On ".aspx.cs" Page: Page_load Bind gridview control: Yeah, we are done now :-) Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!