简体   繁体   English

为什么我在这里得到“指定的演员无效”?

[英]Why am I getting “specified cast not valid” here?

I have a column MyColumn of type INT and I am retrieving some rows with that column 我有一个类型为INT MyColumn列,并且正在使用该列检索某些行

string selectQuery = $@" SELECT [MyColumn] FROM [dbo].[MyTable]
                         WHERE [Id] IN ('{testid_1}','{testid_2}','{testid_3}')
                         ORDER BY [MyColumn]";

var vals = mydb.ExecuteQuery<int?>(selectQuery).ToList();

where db is of type DataContext . 其中dbDataContext类型。

Any idea why this is giving me an invalid cast exception? 知道为什么这会给我一个无效的强制转换异常吗?

这是因为下面的行试图将VARCHAR类型转换为INT

WHERE [Id] IN ('{testid_1}','{testid_2}','{testid_3}')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会收到“指定的演员表无效”的信息? - Why am I getting “Specified cast is not valid.”? 为什么我收到“System.InvalidCastException: Specified cast is not valid”? - Why am I getting "System.InvalidCastException: Specified cast is not valid"? 为什么会收到“指定演员表无效”错误? - Why am I getting a Specified Cast is not valid error? 为什么我得到一个无效的转换异常(“指定的转换无效。”)? - Why am I getting an invalid cast exception ('Specified cast is not valid.')? 尝试将Type强制转换为接口时,为什么会收到“ InvalidCastException:指定的强制转换无效”的信息 - Why am I getting an “InvalidCastException: Specified cast is not valid.” when trying to cast a Type to interface 为什么我在这里得到Unable来抛出异常 - Why I am getting the Unable to cast exception here 为什么会收到此错误:指定的转换无效 - Why getting this error :Specified cast is not valid 如何修复我的“指定演员表无效”错误? - How can I fix my “Specified cast is not valid” error here? 指定的演员表无效。 是因为我试图投射一个对象吗? - Specified cast is not valid. Is it because I am attempting to cast an object? 为什么这个指定的演员无效? - why is this specified cast not valid??
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM