0
从vb.net传递日期变量到SQL Server时,我遇到了同样的问题。我尝试使用上面建议的参数。我仍然面临同样的问题。 Pl指南。从vb.net传递到SQL Server时字符串转换为日期类型
Dim today As String
today = System.DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss")
Dim todate As DateTime = DateTime.ParseExact(today, "MM-dd-yyyy hh:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
SQLCom.CommandType = CommandType.Text
SQLCom.Parameters.AddWithValue("@TODAY", CType(todate, Date))
SQLCom.CommandText = "SELECT DATEDIFF(MM,FORMAT(UPD_DATE,'dd-MM-yyyy'),FORMAT(@TODAY,'dd-MM-yyyy')) AS DATE_DIFF FROM tblEMP WHERE EMPID = '" & ID & "';"
Try
Dim daEmpExp As New SqlDataAdapter
daEmpExp.SelectCommand = SQLCom
SQLConn.Open()
daEmpExp.Fill(dsEmpExp)
SQLConn.Close()
Catch ex As Exception
MsgBox("Sorry!!! " & ex.Message)
Finally
If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
End If
End Try
End If
Return dsEmpExp
它仍然捕获错误“转换日期和/或时间从字符串转换失败。”
您应该编辑您的问题。它的格式不正确。 – Dhwani
我认为你的问题与从MM-dd切换到dd-MM有关 –