Friday, December 17, 2010

isnull is a Saviour

I was trying to query my userName from the database...it was stored as firstname, middlename and lastname and being the dunce I am, I did the simple

Select firstName+' '+MiddleName+' '+lastName as userName from members

Right ?

WRONG !!!

If any of the cols is a null, which usually is for the middle name, the concatanation returns null...

BOOOO

So, now am doing this instead

Select ltrim(isnull(FirstName,'')+' '+isnull(MiddleName, '')+' '+isnull(LastName,'')) as userName from members

and all is well in my world again !!!

Tuesday, December 14, 2010


So I had a gridview which had no data... Now what...
AHhh.. there is empty data template for gridview ... Woo Hoo... here it goes from microsoft site :

The empty data row is displayed in a GridView control when the data source that is bound to the control does not contain any records. You can define your own custom user interface (UI) for the empty data row by using the EmptyDataTemplate property.

<%@ Page language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView EmptyDataTemplate Example</title> </head> <body> <form id="form1" runat="server"> <h3>GridView EmptyDataTemplate Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" runat="server"> <emptydatarowstyle backcolor="LightBlue" forecolor="Red"/> <emptydatatemplate> <asp:image id="NoDataImage" imageurl="~/images/Image.jpg" alternatetext="No Image" runat="server"/> No Data Found. </emptydatatemplate> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. The following query --> <!-- returns an empty data source to demonstrate the --> <!-- empty row. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>