hi friends.in my windows application i am having a 5 textbox,all the 5 textbox datatype as datetime,if i fill the date in all the textbox it will be stored to the database properly,but whenever i try to save the 3textbox values to the database,the remaining two textbox i left empty whenever i click the add button it shows the following error..
String was not recognized as a valid DateTime
whenever i left the textbox as empty,i want to save to the database..pls help me
connection.Open()
cmd = New SqlCommand("insert into test(fdate,tdate,reason)values(@fdate,@tdate,@reason)", connection)
cmd.Parameters.Add("fdate", SqlDbType.DateTime).Value = DateTime.Parse(TextBox1.Text.ToString())
cmd.Parameters.Add("tdate", SqlDbType.DateTime).Value = DateTime.Parse(TextBox2.Text.ToString())
cmd.Parameters.Add("reason", SqlDbType.VarChar).Value = TextBox3.Text
cmd.ExecuteNonQuery()
MessageBox.Show("ok")