Hi, just change your code like below,
DateTime DateConverted;
bool IsValid = DateTime.TryParse(TextBox2.Text.Trim(), out DateConverted);
if(IsValid == false)
{
return;
}
string s1 = "insert into Registration values('"
+ TextBox1.Text + "','"
+ DateConverted + "','"
+ RadioButtonList1.SelectedItem.Text + "','"
+ DropDownList3.SelectedItem.Text + "','"
+ TextBox5.Text + "','"
+ TextBox6.Text + "','"
+ TextBox7.Text + "','"
+ TextBox8.Text + "','"
+ DropDownList1.SelectedItem.Text + "','"
+ DropDownList2.SelectedItem.Text + "','"
+ TextBox9.Text + "')";
And, take a look at
Casting and Type Conversions (C# Programming Guide)[
^]
Follow the guidelines on Solution 1.