c# - “指定的演员阵容无效。” 同时填充 ComboBoxe
问题描述
我正在尝试在按钮单击中填充 ComboBox,但是我收到以下错误:
System.InvalidCastException:“指定的演员表无效。”
public void FillOrgUnit()
{
try
{
using (SqlConnection conn = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=DesignSaoOsig1;Integrated Security=True"))
{
conn.Open();
string query = "SELECT DISTINCT OrgUnitID FROM tblZaposleni_AD ORDER BY OrgUnitID ASC";
SqlCommand cmd = new SqlCommand(query, conn);
using (SqlDataReader saReader = cmd.ExecuteReader())
{
while (saReader.Read())
{
string name = saReader.GetInt32(0).ToString();
ddlStatus.Items.Add(name);
}
}
}
}
catch (Exception)
{
throw;
}
}
我试图转换string name
为,int
但这不起作用。我不知道错误来自哪里。
顺便说一句:OrgUnitId
在数据库中是类型bigint
解决方案
C# 中的 BigInt 等效项是 Int64。
string name = saReader.GetInt64(0).ToString();
推荐阅读
- python - 如何找出估计位置与现实世界位置的标准偏差
- python - Python:在动态文本中查找字符串并将另一个文本放在行前
- javascript - 一个接一个地运行 React 方法
- javascript - Firebase 数据仅在登录和退出后加载
- python - 如何检查 Django Queryset 是否返回多个对象?
- pandas - 使用 Pandas GroupBy 和重新采样的最大保留时间
- typescript - typescript 编译 js 文件 eslint 配置
- python - 如何正确加载带有自定义层的模型?
- spring-boot - camel mbean 管理对象默认不出现
- javascript - 试图找到一种方法来重构我的函数以使其更高效