[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Conditional ? problems

Posted on 2003-12-08
5
Medium Priority
?
275 Views
Last Modified: 2010-04-16
I get an error compiling the follow code saying that theres no implicit conversion between string and sqldatetime, is there away around this without using ifs, i hate having 30000lines for a single function. birthday is obiously a string. thanks

cmd.Parameters["@Birthday"].Value= Birthday !="" ? Birthday : SqlDateTime.Null;
0
Comment
Question by:razziel
[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
  • 3
  • 2
5 Comments
 

Author Comment

by:razziel
ID: 9897934
nevermind :D. ill just use the parse method in SqlDateTime.
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9899930
You have to use it (check also ParseExact method) because the parameter knows it is of type DateTime and does not allow string values directly. Be careful with date formats, Parse is very powerful and also a dangerous function.
0
 

Author Comment

by:razziel
ID: 9901039
well the parameter does take strings even tho its a SqlDateTime, but it raises an exception if its not in the right format. I guess both the true result and false results have to be of the same type, i hadnt tested tho. i guess ill have to validate the text just after the user types it on the textbox. if anyone can give me a good sample of how to do this, like those nice validators on webforms, ill give the points. thanks
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 9902471
Why don't you use directly a DateTimePicker? It has a checkbox to disable it (the same as having an empty string in your case) and can be set to show the date in a lot of different formats and gives you directly the value in an object ot type DateTime. So you would write a code like:

cmd.Parameters["@Birthday"].Value= BirthdayDateTimePicker.Checked ? BirthdayDateTimePicker.Value : SqlDateTime.Null;

You only have to enable the checkbox, i.e. put the DatePicker's ShowCheckBox property to true.
0
 

Author Comment

by:razziel
ID: 9904810
good idea, thanks. i dont know why was i even bothering using a textfield when theres such a nice control. =)

theres your points
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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