Hello everybody. In an insert routine I get a "FormatException was unhandled" - "Failed to convert parameter value from a String to a DateTime." error when attempting to insert a record. The error points to myCommand.ExecuteNonQuery(). In the record insert attempt I put values in txtFirstName and txtLastName and purposely leave the rest of the fields blank. In the table FirstName and LastName must have values. For the rest of the columns NULL is allowed. How do you guys and gals handle this situation in a graceful way? I haven't coded any validation yet. I don't want to insert '0' or 'n/a' or anything like that in the table where NULLs are permitted. Would someone please share their insight?
Code:Dim myCommand As SqlCommand myCommand = New SqlCommand myCommand.Connection = CN myCommand.CommandText = "sInsertGuide" myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.Add("@FirstName", SqlDbType.VarChar, 50, ParameterDirection.Output).Value = Me.TxtFirstName.Text myCommand.Parameters.Add("@LastName", SqlDbType.VarChar, 50, ParameterDirection.Output).Value = Me.TxtLastName.Text myCommand.Parameters.Add("@Qualification", SqlDbType.VarChar, 2048, ParameterDirection.Output).Value = Me.TxtQuailfication.Text myCommand.Parameters.Add("@DateOfBirth", SqlDbType.DateTime, 10, ParameterDirection.Output).Value = Me.TxtDateOfBirth.Text myCommand.Parameters.Add("@DateOfHire", SqlDbType.DateTime, 10, ParameterDirection.Output).Value = Me.TxtDateOfHire.Text myCommand.ExecuteNonQuery()




Reply With Quote