0

So I'm trying to create the following: I have 3 Dropdowns (one for the day, another for the month and other for the year) and I want to concatenate these three elements on the SQL Database.

Basically, it's a Birthday date I want to save.

Pictures:

Where the user select the Birthday Date

Where I want to save the Date 'all together' (day, month and year)

Thank you for your help!

4
  • Use string.Format in c# before saving it to the database. Commented Jun 26, 2017 at 16:23
  • Check out this link stackoverflow.com/questions/1032495/… Commented Jun 26, 2017 at 16:23
  • it didn't help me much.... I can't understand what is being done :\ Commented Jun 26, 2017 at 16:41
  • If your database wants a DateTime (and I hope it does), simply use var dateOfBirth = new DateTime(year, month, day); and insert that into your database. Commented Jun 26, 2017 at 16:47

1 Answer 1

0

Get the date and using following snippet to store the value to database.

var date = new DateTime(year, month, date);


        SqlCommand cmd = new SqlCommand("INSERT INTO <table> (<column>) VALUES (@value)", connection);
        cmd.Parameters.AddWithValue("@value", date);

        cmd.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.