System.FormatException:String未被识别为有效的DateTime。在System.DateTimeParse.Parse

时间:2016-08-12 21:40:49

标签: c#

出生日期的sql参数

var img = $('div > img');
$.each(img, function(i) {
  if ( !img[0] ) {
     img.remove();
     setTimeout(function(){
        $('.main').append(img);
     }, i * 2000);
  }

});

转换日,月和年`

.main {
   width: 200px;
   height: 80px;
   padding: 10px;
   overflow: visible;
   border: 2px solid red;
}
.div1,
.div2,
.div3 {
   width: 200px;
   height: 80px;
   background: #ccc;
   float: left;
   position: absolute;
}
.div2 {left:232px;}
.div3 {left:437px;}

class jfunction

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
       
   <div class='div1'>
      <img src="#" alt="">
   </div>
   <div class='div2'>
      <img src="#" alt="">
   </div>
   <div class='div3'>
      <img src="#" alt="">
   </div>

</div>

在提交时显示此错误

 SqlParameter dayParameter = new SqlParameter("@day", SqlDbType.Int);
            SqlParameter monthParameter = new SqlParameter("@month", SqlDbType.Int);
            SqlParameter yearParameter = new SqlParameter("@year", SqlDbType.Int);

1 个答案:

答案 0 :(得分:1)

声明

dayParameter.Value = Convert.ToString(Convert.ToDateTime(Jfunctionparents.GetSystemDate().Substring(0, 2)));

看起来逻辑错误,系统无法将Jfunctionparents.GetSystemDate().Substring(0, 2)的输出转换为DateTime,因为它是一个长度为2的字符串。

我认为您想要的只是当天,因此无需将Jfunctionparents.GetSystemDate().Substring(0, 2)转换为DateTime

陈述应如下:

dayParameter.Value = Int32.Parse(Jfunctionparents.GetSystemDate().Substring(0, 2));
monthParameter.Value = Int32.Parse(Jfunctionparents.GetSystemDate().Substring(3,2));
yearParameter.Value = Int32.Parse(Jfunctionparents.GetSystemDate().Substring(6,4));