Solved

Date display in Datagrid

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

679 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