DB COLUMN EMPTY DISPLAY

Posted by Gokul under Regular Expressions on 12/14/2010 | Points: 10 | Views : 1035 | Status : [Member] | Replies : 2
Dear Friends
I have a column empty in a table in my DB. I am loading the table from my DB into grid and binding the table to the grid. Now the grid displays the table but the empty columns in that table in DB are displayed with empty message itself. Instead of displaying the empty column, i want to display as Null in it. CAn any one help ???



Regards
Gokul.N

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Vuyiswamb on: 12/14/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
You can do that from the SQL Side, Lets say you have a Query like this

SELECT FIRSTNAME, LASTNAME FROM CUSTOMER 



Now if you have a record that have FirstName with an empty string, then you can twik your query like this


SELECT 

LASTNAME ,
CASE FIRSTNAME
WHEN ' ' THEN NULL
ELSE OrderAmount END AS [ORDER]
FROM Orders


i used the Case , to check if there is an empty string, if there is then return null.


Thank you for posting at Dotnetfunda
[Administrator]

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 12/14/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
In the Grid where you are expecting Empty column, write following code snippet, this is basically a Template field that will add another column in your Grid.

<asp:TemplateField HeaderText="Delivery Status?" HeaderStyle-HorizontalAlign="Left">

<ItemTemplate>
<%# Eval("IsDelivered").ToString().Length.Equals(0) ? "null" : Eval("IsDelivered").ToString() %>
</ItemTemplate>
</asp:TemplateField>


I am assuming that your column whose data is empty is "IsDelivered", you can change the column name accordingly.

Very fast Vuyiswa! Whatever Vuyiswa has answered will work from database side, my solution will work from application side.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response