Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

masked textbox

Posted on 2006-06-12
5
Medium Priority
?
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1600 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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