Solved

Date display in Datagrid

Posted on 2004-09-19
6
621 Views
Last Modified: 2012-08-14
Hi,

I have an editable datagrid with several date columns, that users need to update at different times.
My SQL server table accepts null for the date column. At first most of columns are null until someone start to enter datas.

If nothing has been entered the datagrid displays an empty cell (which is fine).
If , I update some columns in the datagrid but do not update any date column, the date of 01/01/1900 is automatically generated by the database. After rebinding the datagrid some date columns that are supposed to remain empty now display the 01/01/1900 date. This because the add.paramter in the update event passes an empty string to the database and the field is no longer null.

To work around this problem I am looking for help to create a function that could return an empty string in the datagrid if the date in the database is 01/01/1900.

I have tried to make is work but I am facing casting problems between string, date format...


0
Comment
Question by:pascalmartin
6 Comments
 
LVL 1

Expert Comment

by:keijerjh
ID: 12096134
Hi,

Maybe you can create an expression column.
Sample:
DataTable.Columns.Add("DISPLAY_DATE",TypeOf(String),Iif(DATE_COLUMN=#01-01-1900, "", DATE_COLUMN))

You can also read the article from Microsoft:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/data05312002.asp


Greetings,
Yelle
0
 
LVL 1

Expert Comment

by:mlpk_tyr
ID: 12099951
hi,
i found your problem ia with the update operation. you can avoid this result at the update phase only

as you have said the  add.paramter in the update event passes an empty string , you can validate the value if it is a blank value then set it to null. if there is any value then try to form a date object and validate it. if validation fails then raise an error and set it back to user or if its valid then pass it to DB.

so by this  you do validation at grid which avoids overhead of validating at DB. hope you understand the suggestion.

hope this helps,
mlpk_tyr
0
 

Author Comment

by:pascalmartin
ID: 12101864
Hi,
Thanks for your valuable comments. I have somehow managed to get the desired result the following way:
The update event inserts and empty string in the DB date column, this empty string is interpreted by the DB as '01-01-1900', then I created in my stored procedure a second update that set the date column to null if the date column is '01-01-1900'.
After rebinding the datagrid the date column displayed is back to a null value and shows an empty cell.

This a very simple but effective way, it may not be very academically correct but it works, all the work happens in the DB and I d'ont have to create any lenghty code in my page behind.

rgds.

0
 

Author Comment

by:pascalmartin
ID: 12520401
I did find the solution by myself and explained it to the participant.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12542488
PAQed, with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now