Parsing content from textboxes efficiently

T

taa

Hi there
I’m trying to come up with a smart way of parsing content from
textboxes in C#. I have about 7-10 boxes with different content;
dates, times, numbers and text that has to be parsed and inserted into
my database.
Of course the obvious solution is to make a lot of if’s and parse each
box one at the time with the properties I know and catch all
exceptions on the way, if any, but does anyone has an idea of a
smarter way of doing this?
Thought about making a list of the boxes with content, so I don’t have
to waste time parsing the empty ones and catching exceptions.

An example of how I'm parsing a Textbox containing a date:
if (BeginTime.Text != "__:__:__")
{
ad.DateTimeBegin = DateTime.ParseExact(BeginDate.Text,

CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern,
null);
}


Regards
Lasse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top