2012-07-16 62 views

回答

0

WinForms:datepicker有一個屬性稱爲「價值」,它是DateTime數據類型。使用它。

Web窗體:如果您在使用JQuery,只是做

var date = $("#myDateControl").val(); 

你那麼如何存儲的價值取決於你所使用的數據庫(SQL,甲骨文等),無論您是使用實體框架(或其他ORM)或不...給予更多的細節,如果你想更徹底的答案。

編輯

根據您的意見,我會做這樣的事情:

using (var connection - new SqlConnection("my connection string")) 
{ 
    using (var command = connection.CreateCommand()) 
    { 
     command.CommandText = string.Format("INSERT INTO Stu_inf(Enrollno, Firstname, Lastname, Birthdate) VALUES ('{0}', '{1}', '{2}', '{3}')", txtEnrollno.Text, txtFname.Text, txtLname.Text, mtxtBdate.Value.ToString("yyyy-MM-dd")); 
     connection.Open(); 
     command.ExecuteNonQuery(); 
     connection.Close(); 
    } 
} 

我寫了這一切從內存中,所以你可能會得到一個小的語法錯誤或東西..但這是主意......希望它有幫助

+0

我使用SQL Server ,我只想爲Windows窗體 實際上,我把日期時間選擇器 用戶 用戶選擇一個日期 然後我要添加該日期在數據庫生日柱 串查詢=「插入Stu_info(Enrollno,名字,姓氏,生日,)的值(」 + txtEnrollno.Text +「 ,'「+ txtFname.Text +」','「+ txtLname.Text +」','「+ mtxtBdate.Text +」'「)」; SqlCommand cmd = new SqlCommand(Query,conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); – 2012-07-16 03:12:11

+0

現在這個我寫我的代碼,但不工作.... bcoz我不能使用 mbate.text bcoz這是日期時間選擇器控制,這就是爲什麼 sooo plzzz幫我出 – 2012-07-16 03:13:36

+0

我更新了上面的答案。如果有幫助,請接受它爲「答案」。 – Matt 2012-07-16 03:32:44