No function matches the given name and argument types

Your function has a couple of smallint parameters. But in the call, you are using numeric literals that are presumed to be type integer. A string literal or string constant (‘123’) is not typed immediately. It remains type “unknown” until assigned or cast explicitly. However, a numeric literal or numeric constant is typed immediately. The … Read more

Lexical cast from string to type

I like using locate, which works on built-in types: >>> from pydoc import locate >>> locate(‘int’) <type ‘int’> >>> t = locate(‘int’) >>> t(‘1’) 1 …as well as anything it can find in the path: >>> locate(‘datetime.date’) <type ‘datetime.date’> >>> d = locate(‘datetime.date’) >>> d(2015, 4, 23) datetime.date(2015, 4, 23) …including your custom types: >>> … Read more

Invalid cast from ‘System.Int32’ to ‘System.Nullable`1[[System.Int32, mscorlib]]

You have to use Nullable.GetUnderlyingType to get underlying type of Nullable. This is the method I use to overcome limitation of ChangeType for Nullable public static T ChangeType<T>(object value) { var t = typeof(T); if (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) { if (value == null) { return default(T); } t = Nullable.GetUnderlyingType(t); } return (T)Convert.ChangeType(value, t); } … Read more

Why should casting be avoided? [closed]

You’ve tagged this with three languages, and the answers are really quite different between the three. Discussion of C++ more or less implies discussion of C casts as well, and that gives (more or less) a fourth answer. Since it’s the one you didn’t mention explicitly, I’ll start with C. C casts have a number … Read more

How should I cast in VB.NET?

Those are all slightly different, and generally have an acceptable usage. var.ToString() is going to give you the string representation of an object, regardless of what type it is. Use this if var is not a string already. CStr(var) is the VB string cast operator. I’m not a VB guy, so I would suggest avoiding … Read more

Change type of varchar field to integer: “cannot be cast automatically to type integer”

There is no implicit (automatic) cast from text or varchar to integer (i.e. you cannot pass a varchar to a function expecting integer or assign a varchar field to an integer one), so you must specify an explicit cast using ALTER TABLE … ALTER COLUMN … TYPE … USING: ALTER TABLE the_table ALTER COLUMN col_name … Read more