Solved

Date display in Datagrid

Posted on 2004-09-19
6
622 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML table 7 65
Fixed div within Bootstrap carousel item 11 53
Firebug on Firefox 50 2 66
File download script VBSCRIPT fail on download PPT files 2 31
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

943 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

16 Experts available now in Live!

Get 1:1 Help Now