473,725 Members | 2,349 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 12011
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
14287
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
10409
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
2267
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
4334
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
4405
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
6519
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
9108
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
1471
by: va | last post by:
Why does this property "DateTime?" compile? public DateTime? test { get { return DateTime.Now; } }
0
1280
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
8748
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
9393
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...
0
9092
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8072
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
6695
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
6000
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4506
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...
1
3212
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2622
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.