I am working on winforms using c# where I have a class User having datetime dob variable whose value is inserted into database (type of database column is date).
the function in user class is :
        {
            string format = "yyyy-MM-dd";
            if (mail.IsMatch(id) && password.Length >= 8 && password == confrmpass)
            {
                con.Open();
                cmd = new SqlCommand($"insert into UserInfo (Username,Password,[Full Name],Email,Address,[Date of birth]) values ('{username}','{password}','{name}','{id}','{address}','{dob.ToString(format)}'", con);                    
                cmd.ExecuteNonQuery();
            }
        }
next this class object is made in Form:
User user1 = new User();
  user1.register(textname.Text.ToString(),textemail.Text,textaddress.Text,textuser.Text,textpassword.Text,textconfirmpass.Text,metroDateTime1.Value.Date);
where the date is passed by using the datetimepicker.
Now I am having error
'Incorrect syntax near '2020-08-31'.'
why I am having error when the sql date format is same. How can I solve this.
 
    