简体   繁体   中英

How to resolve the error “String was not recognized as a valid Date Time in Vb.net ”

My code behind is as follows I want to enter the date as per displayed on the TextBox4 front end

 Protected Sub btnSave_Click1(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

    Dim dt2 As OleDbParameter
    dt2 = cmd.CreateParameter
    dt2.OleDbType = OleDbType.Date
    Dim dt As String = TextBox4.InnerText
    dt2.Value = DateTime.ParseExact(dt,"M/dd/yyyy", Nothing)
    dt2.ParameterName = "@StartDate"
    cmd.Parameters.Add(dt2)

End Sub

My front end code in aspx is as follows

 <div class="container" id="TextBox4" runat="server" width="181px"  bordercolor="Black" borderstyle="Solid">
        <div class="row">
          <div class='col-sm-6'>
            <div class="form-group">
              <div class='input-group date' id='datetimepicker1'>
                <input type='text' class="form-control" />
                <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div>
            </div>
          </div>
          <script type="text/javascript">
              $(function () {
                  $('#datetimepicker1').datetimepicker();
              });
          </script>
        </div>
      </div>
Protected Sub btnSave_Click1(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

Dim dt2 As OleDbParameter
dt2 = cmd.CreateParameter
dt2.OleDbType = OleDbType.Date
dt2.Value = = TextBox4.Text
dt2.ParameterName = "@StartDate"
cmd.Parameters.Add(dt2)

End Sub


Edited like this and it works thanks everyone for the feedback and help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM