Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

"String was not recognized as a valid DateTime."

M getting this error on submit button click. my "warranty" column is of text type and "warrantytill" column is of date type in my table. Now i am saving the values according to warranty text value i.e) if warranty.text="yes" take d value from respective textbox. if warranty text="no" then it should save null or nothing.


How do a do that.

Thanks
Posted
Comments
Prasad_Kulkarni 12-Mar-13 2:55am    
Show your code..
Member 9881481 12-Mar-13 3:08am    
string Check1 = ddlwarranty.SelectedItem.Text;
if (Check1 == "Yes")
{
SqlParameter WarrantyTillparam = new SqlParameter("@WarantyTill", SqlDbType.Date);
WarrantyTillparam.Value = txtwarrantytill.Text;
cmd.Parameters.Add(WarrantyTillparam);
}
else
{
SqlParameter WarrantyTillparam = new SqlParameter("@WarantyTill", SqlDbType.Date);
txtwarrantytill.Text = "00-00-0000";
WarrantyTillparam.Value = txtwarrantytill.Text;
cmd.Parameters.Add(WarrantyTillparam);
}
Member 9881481 12-Mar-13 5:08am    
i had changed those lines with your code bt its still giving same error
Shubham Choudhary 12-Mar-13 2:58am    
are you using mysql server!
Member 9881481 12-Mar-13 3:07am    
sql server 2010

1 solution

Try this:
C#
SqlParameter WarrantyTillparam = new SqlParameter("@WarantyTill", SqlDbType.Date);
DateTime yourDateTime = DateTime.ParseExact(txtwarrantytill.Text, "yyyyMMdd", CultureInfo.InvariantCulture);
WarrantyTillparam.Value = yourDateTime;
//WarrantyTillparam.Value = txtwarrantytill.Text;  
cmd.Parameters.Add(WarrantyTillparam);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900