I am trying to update a DateTime object into a datetime field of a sql (SQL Server 2000) database.
I have the following function
Public Sub Update(ByVal lastlogin as DateTime)
Using slqupdate as SqlCommand = _connection.CreateCommand()
sqlupdate.CommandType = CommandType.Text
sqlupdate.CommandText = "UPDATE myTable SET LastLogin = @lastlogin WHERE ID = 2"
updatelastlogin = sqlupdate.CreateParameter()
updatelastlogin.ParameterName = "@lastlogin"
updatelastlogin.DbType = SqlDbType.DateTime
updatelastlogin.Value = lastlogin
slqlupdate.Parameters.Add(updatelastlogin)
sqlupdate.ExecuteNonQuery()
End Using
End Sub
Attempting to call it as follows Update(DateTime.Now) produces the following Exception:
Failed to convert parameter value from a DateTime to a Decimal.
I am not sure what I've done wrong, does anybody know?