Reputation: 49
I have 3 drop down list having Date,Month ,Year.So when Updating I want this 3 Field to be a single Datafield in Sql Database. Iam using Asp.Net 2.0 Version(VB.Net).(Now these 3 Dropdown list values are saved as 3 Datafields in sql Database)
Upvotes: 2
Views: 2830
Reputation: 838
Join up the values:
month + "/" + day + "/" + year
and use DateTime.Parse() or DateTime.TryParse() to convert them to a date. If you are concerned about the date format for your culture, pass in a CultureInfo object. Add your own validation as needed.
http://msdn.microsoft.com/en-us/library/1k1skd40.aspx
Not foolproof, but it might satisfy your requirement.
Upvotes: 0
Reputation: 20360
Why not use a date/time picker instead? It seems to me to be a better idea than your own triplet of day, month and year.
Upvotes: 5
Reputation: 97861
I take it you're using a SqlCommand for this? Here's some sample, non-compiling code which I'll whip up for you here:
Dim cmd as SqlCommand("update tableX set dt = @var where ID = 1");
cmd.Parameters.AddWithValue("@var", new DateTime(CInt(day.SelectedValue), CInt(month.SelectedValue, CInt(year.SelectedValue)));
cmd.ExecuteNonQuery();
Upvotes: 2