?
Solved

Date display in Datagrid

Posted on 2004-09-19
6
Medium Priority
?
630 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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