473,657 Members | 2,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Set Empty String in "System.DateTim e?" 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 12003
Just to add... I am using .net 2.0, visual studio .net 2005.

"Sugandh Jain" <su**********@n irvana-sol.comwrote in message
news:uo******** ******@TK2MSFTN GP02.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.Componen tModel;
using System.Diagnost ics;

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<MyD atalist = new BindingList<MyD ata>();
list.Add(new MyData());
using (Form f = new Form())
using (DataGridView dgv = new DataGridView()) {
dgv.AutoGenerat eColumns = 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**********@n irvana-sol.comwrote in message
news:uo******** ******@TK2MSFTN GP02.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
14281
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 control on windows forms, there is the checkbox that can indicate an empty date value. there is no such thing for the data type DateTime.
8
10404
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 is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
0
2261
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 and run an update to database using the same XML string, (using SQL parameters to pass the selectsinglenode), the XML always shows the NULL values as an empty string "". This is then updating the database with an empty value rather than keeping...
8
4329
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 procedure and must save either a null or a real date. However, passing a hardcoded "null" to call this function causes a compilation error : cx.cs(136): Argument '16': cannot convert from '<null>' to 'System.DateTime'
2
4394
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 not recognized as a valid datetime" Our code looks like this:
2
6512
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 field. I declared a variable as a date datatype and when it´s going to receive the content of the text field, it shows the following error "Cast from
2
9101
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 XmlValidatingReader in .NET 1.1. If the document contains the above element with no data, for example:
2
1467
by: va | last post by:
Why does this property "DateTime?" compile? public DateTime? test { get { return DateTime.Now; } }
0
1278
by: dba123 | last post by:
Why am I getting this error below? This is the correct implementation as far as I can see. Reference (http://msdn2.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.getcachedependency.aspx) Error: 'MyVirtualFile.GetCacheDependency(string, System.Collections.IEnumerable, System.DateTime)': no suitable method found
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.