Solved

masked textbox

Posted on 2006-06-12
5
443 Views
Last Modified: 2012-06-21
I am trying to use the Masked TextBox for date.

In the database data is stored as 1/12/2006 not 01/12/2006

I specified the _ _/_ _/_ _ _ _ for the mask and it works fine for entries with double digits for the month like
12/01/2006.  If I have 1 digit months 1/1/2006 then it stores 11/20/06__  

It shifts everthing to fit the mask.  I changed the mask to _/_ _/_ _ _ _ and it works fine for the single months, but then it gets messed up for the double digit months.

How can I make it stop shifting over?


thanks.
0
Comment
Question by:yanci1179
  • 4
5 Comments
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889519
you cant know if the month will be with one or two digits, so you will have to use the two digits format.

There will be a moment when you use the text inside your masked textbox to know a date. At this moment you can just say that a mont with one digit must be written as 0x (for example 01/01/1980) or you can just show at the text of the masked textbox (which could be like 1 /1 /1980) and make a usefull format like 01/01/1980 out of it.

If I have 1 digit months 1/1/2006 then it stores 11/20/06__  (i tryed to do it with 1 digit and it works fine for me so it must be a problem of your application)
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889557
maybe you are passing the string to date without handling the spaces first?
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889614
//In the database data is stored as 1/12/2006 not 01/12/2006

Sorry, i din't read this,
yyes you are right, the value is wrong then.

You just have to do aut of dates like 1/2/1981 dates like 01/02/1981

0
 
LVL 10

Assisted Solution

by:dkloeck
dkloeck earned 400 total points
ID: 16889719
i tryed it with this code and it works fine:

string dbDate = "1/2/1982";
string newDate = dbDate;
if (newDate.IndexOf("/") < 2)
    newDate = "0" + newDate;
if (newDate.IndexOf("/", 3) < 5)
    newDate = newDate.Insert(3, "0");
maskedTextBox1.Text = newDate;
0
 
LVL 5

Accepted Solution

by:
t_itanium earned 100 total points
ID: 16891774
when you get the data from the database make a simple check..:

string date="";
string day=dbDate.Day.ToString();
string month=dbDate.Month.ToString();;
string year=dbDate.Year.ToString();;

if (day.Length()==2)
{
     date+=day;
}
else
{
    date+="0"+day;  
}

date+="/";

if (month.Length()==2)
{
     date+=month;
}
else
{
    date+="0"+month;  
}

date+="/";

if (year.Length()==4)
{
     date+=year;
}
else
{
    date+="20"+year;  
}

then assign the value of date to the textbox..



cheers
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now