2017-06-26 25 views
0

所以我試圖創建以下內容:我有3個下拉菜單(一天爲一天,另一個爲本月和其他年份),我想連接這三個SQL數據庫上的元素。從3個不同的DropdownList中取數據到一個SQL數據庫

基本上,這是我想保存的生日日期。

圖片:

Where the user select the Birthday Date

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

謝謝您的幫助!

+0

在將c#保存到數據庫之前,使用'string.Format'。 – ISHIDA

+0

看看這個鏈接 https://stackoverflow.com/questions/1032495/insert-datetime-value-in-sql-database-with-c-sharp –

+0

它沒有幫助我太多....我可以' t理解正在做什麼:\ –

回答

0

獲取日期並使用下面的代碼片段將值存儲到數據庫。

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(); 
+0

對不起,這可能聽起來很愚蠢(而且這很愚蠢)。但我無法真正理解你的代碼......我不太明白我應該把它放在哪裏......對不起,我有點新的東西,但如果你願意,可以給我更多的線索,我會非常感謝:)哦,謝謝你的時間 –

相關問題