字符串未被识别为有效日期

本文关键字:有效日期 识别 字符串 | 更新日期: 2023-09-27 17:56:35

protected void Button1_Click(object sender, EventArgs e)
{
    con.Open();
    if (enrl.Text == "")
    {
        Label1.Text = "Enter Enrollment Number first";
    }
   int enroll = int.Parse(enrl.Text);
  string birth = Convert.ToDateTime(calendar.Text).ToShortDateString();           
   string fullname = name.Text;
   string father = fname.Text;
   string Occ = fOcc.Text;
   string mname = mothername.Text;
   string school = prevschool.Text;
   string gen = dropGen.Text;
   int mobile = int.Parse(mob.Text);
   string mail = email.Text;
   string rel = DropRelgn.Text;
   //string adm = Convert.ToDateTime(admDate.Text).ToShortDateString();
   string facility = hostel.Text;
   string ad = address.Text;
   cmd.CommandText = "insert into Registration_N(enroll,FullName,AdmissionDT,DOB,Religion,Gender,Father,FOccup,address,Mobile,dayHostel,previousSchool,motherName,email)  values (" + enroll + ",'" + fullname + "','" + adm + "', '" + birth + "' , "+rel+","+father+" , "+fOcc+","+ad+",'"+mobile+"',"+hostel+","+prevschool+","+mname+","+email+")";
   cmd.ExecuteNonQuery();
   da.Update(ds,"Registration_N");
   Label1.Text = "RECORD ADDED";
   con.Close();
}

字符串未被识别为有效日期

检查您的SQL服务器期望获得的格式是什么(例如MM/dd/yyyy)以及代码结果的格式(例如dd/MM/yyyy)