473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to Set Empty String in "System.DateTime?" The nullable DateTimeType.

Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it shows
it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #1
3 11955
Just to add... I am using .net 2.0, visual studio .net 2005.

"Sugandh Jain" <su**********@nirvana-sol.comwrote in message
news:uo**************@TK2MSFTNGP02.phx.gbl...
Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it
shows it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #2
How do I get this nullable reference type to represent an empty
string?/
Actually, that's a nullable value type, which is itself a value type.
However, it all looks fine for me (see below) - but I guess it comes
down to the format options on the columns, assuming that you are using
proper TypeConverter usage and not just calling .ToString() yourself:

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics;

class MyData {
private DateTime? a, b, c;
public DateTime? A { get { return a; } set { a = value; } }
public DateTime? B { get { return b; } set { b = value; } }
public DateTime? C { get { return c; } set { c = value; } }

public MyData() {
A = null; // null
B = new DateTime(); // non-null zero
C = DateTime.Now; // non-zero
}
}

class MyProgram {

static void Main() {
BindingList<MyDatalist = new BindingList<MyData>();
list.Add(new MyData());
using (Form f = new Form())
using (DataGridView dgv = new DataGridView()) {
dgv.AutoGenerateColumns = true;
dgv.Dock = DockStyle.Fill;
dgv.DataSource = list;
f.Controls.Add(dgv);
Application.Run(f);
}
}
}
Mar 29 '07 #3
Thanks I got it. Set the Null Text for the column in the grid to empty
string. and left the value of the volumn to be null.
So, it does not show a default date, but the empty string..

Thanks,
Sugandh

"Sugandh Jain" <su**********@nirvana-sol.comwrote in message
news:uo**************@TK2MSFTNGP02.phx.gbl...
Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it
shows it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Picho | last post by:
Hi all, Does anyone know of a GOOD explaination why the DateTime type is a value time (cannot be null) and furthermore does not provide a DateTime.Empty value? when using a DateTimePicker...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
0
by: Dana | last post by:
I am using the XMLTextWriter to build an XML string and pass it to the XMLDocument. When I get the data from SQL Server, some of the values passed to the XML are NULL in the database. When I try...
8
by: craigkenisston | last post by:
I have a generic function that receives a couple of datetime values to work with. They can or cannot have a value, therefore I wanted to use null. This function will call a database stored...
2
by: GossTremontTech | last post by:
Hi, We have a webservice that generates an xml string that has a empty/null datetime field (<OurDate></Ourdate>). When we use ReadXML read in the serialized string we get the error: "string...
2
by: zafzal | last post by:
Hello all, I have a textbox in my asp.net (vb.net) aplicattion, I need to assign it's value to a Variable of type DATE, but it's not a required field, so sometimes I want to send a blank...
2
by: craig.wagner | last post by:
I have an element in my schema defined as follows: <xs:element name="BillingDate" type="xs:dateTime" nillable="true" minOccurs="0"/> I use the schema to validate incoming documents using an...
2
by: va | last post by:
Why does this property "DateTime?" compile? public DateTime? test { get { return DateTime.Now; } }
0
by: dba123 | last post by:
Why am I getting this error below? This is the correct implementation as far as I can see. Reference...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.