[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Date display in Datagrid

Posted on 2004-09-19
6
Medium Priority
?
631 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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

649 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