|
I have a table, where I save info about some documents we should have or allready has send to our customer - when the document issend a date is set in the field.
On the other hand - when no document is send yet - then NO DATE is set - but if I look directly in the table - the value "01-01-1900 00:00:00" is "set" in the field.
I show the data from the table in a datagridview with an UNBOUND DataGridViewCheckBoxColumn to enable users to define that THIS customer should have a document AND for these rows is the data "01-01-1900 00:00:00" shown in the datagridview too - for ALL other row the data is empty (not shown - blanc)
How can I prevent the date "01-01-1900 00:00:00" to be shown i ALL rows ?
Best regards
KSO, Denmark | | PSAKSor Monday, May 25, 2009 8:09 AM | Hi, You can achieve this in 2 ways: 1. In the SQL query where you fetch the data from database, skip fetching records where date is as specified by you(01-01-1900 00:00:00). Something like: SELECT * FROM TABLE1 WHERE <YOUR CONDITION> AND DATE_FIELD <> '01-01-1900 00:00:00'. You would need to do few alterations depending on your datatype etc.
2. Before binding the data from datatable to datasource of datagridview, you can remove the unwanted records by looping through and checking for (01- 01-1900 00:00:00). Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such.- Marked As Answer byAland LiMSFT, ModeratorTuesday, May 26, 2009 4:54 AM
- Unmarked As Answer byPSAKSor Tuesday, May 26, 2009 5:50 AM
-
| | Abhijeet Lakra Tuesday, May 26, 2009 1:53 AM | I think we misunderstands each other.
If I select with condition date_Field<>'01-01-1900 00:00:00' then I'll get NO rows back !
I think it has to do with the date field can NOT have the value NULL for "not entered" - if no date is entered the value is '01-01-1900 00:00:00'.
I too wonder why only SOME of the rows in the datagridview is showing '01-01-1900 00:00:00' - the date field i both cases HAS no date entered !
Best regards
KSO, Denmark | | PSAKSor Tuesday, May 26, 2009 5:54 AM | Advice as per current understanding: When you save data in the Table, you can save "DateTime.MinValue" in the database for scenario when documents are not sent. The ADVANTAGE with this would be- in the datagrid, Blank values would automatically be displayed for value(DateTime.MinValue).
And, I am not so comfortable in understanding -
"I show the data from the table in a datagridview with an UNBOUND DataGridViewCheckBoxColumn to enable users to define that THIS customer should have a document AND for these rows is the data "01-01-1900 00:00:00" shown in the datagridview too - for ALL other row the data is empty (not shown - blanc)
How can I prevent the date "01-01-1900 00:00:00" to be shown i ALL rows ?"
Questions: So, you are having a column to display the dates? And, for records with date as "01-01-1900 00:00:00", you are viewing this particular date in datagridview? What about records with a valid date.. Date-column for those records are displayed as blank?
And, you prefer displaying blank value instead of "01-01-1900 00:00:00"? Is that what you mean?
Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. | | Abhijeet Lakra Tuesday, May 26, 2009 7:18 AM | "So, you are having a column to display the dates?" - yes
"records with date as "01-01-1900 00:00:00", you are viewing this particular date in datagridview? " - yes
"What about records with a valid date.. Date-column for those records are displayed as blank?" - no, they are showing the right date for sending the document
"And, you prefer displaying blank value instead of "01-01-1900 00:00:00"? " - yes
;.)) - communication is allwaysa bit tricky !
Best regards
KSO, Denmark | | PSAKSor Tuesday, May 26, 2009 7:24 AM | Yes, communication can be tricky specially over text message exchange. :)
What about- Advice as per current understanding: When you save data in the Table, you can save "DateTime.MinValue" in the database for scenario when documents are not sent. The ADVANTAGE with this would be- in the datagrid, Blank values would automatically be displayed for value(DateTime.MinValue).
>> The value for "DateTime.MinValue" = '1/1/0001 12:00:00 AM'. Datagrid recognizes this value and displays blank by default.
Did you try this? You can always make a small test to verify. it would work fine. :) Regards,
Lakra :)
- If the post is helpful or answers your question, please mark it as such. | | Abhijeet Lakra Tuesday, May 26, 2009 8:15 AM | In my case DateTime.MinValue is "01-01-1753 12:00:00" and I CAN store it in the field in the db.
I test the displaying later - buzy somewhere else - sorry !
Best regards
KSO, Denmark | | PSAKSor Tuesday, May 26, 2009 9:38 AM | Aland Li: OK - I'll check later Best regards
KSO, Denmark | | PSAKSor Tuesday, May 26, 2009 9:41 AM | Hi PSAKSor,
From your description, you wanted to set the data of the date time column to null when you add a new row. But the result is not what you expected, the data was not null. All the added values of that column are the same, as if the column has a default value.
I did some test below: 1. Create a table using a sql script below. The second column of the table has a default value �008-01-01�
CREATE TABLE [dbo].[MyTable](
[Id] [int] NULL,
[logTime] [datetime] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [DF_MyTable_logTime] DEFAULT ('1/1/2008 12:00:00 AM') FOR [logTime]
GO
2. Add a new row the data of whose second column is not set. Use a insert sql to update the table. As a result, the data of the new row’s second column is the default value. The insert sql and the new row’s data is below: Sql: insert MyTable (Id) values (111) New row: 111(column1), �/1/2008 12:00:00 AM�column2)
3. Use SqlDataAdapter to fill a table and add a new row to the table. The second column of the new row is also not set. The result is the same to step2.
4. I modified the definition of the table and set the second column null, then repeated the steps above. The results are the same.
According to the test results above, I think the key problem is mostly related to the default value of the data column. So I suggest that you need to remove the default value of the column and make it can be null. If I have misunderstood you, please feel free to tell me, thanks.
Best regards, Aland Li | | Aland Li Saturday, May 30, 2009 8:58 AM |
|