错误:特定演员表无效 [英] error:specific cast is not valid

查看:87
本文介绍了错误:特定演员表无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在oracle 11g数据库中运行了代码。 sql>从treat_info,patient_table中选择count(*),其中treat_info.pid = patient_table.pid;

结果是 count(*)= 0

但是在C#Windows应用程序中发生错误。



I have run the code in oracle 11g database. sql>select count(*) from treat_info,patient_table where treat_info.pid=patient_table.pid;
The result is count(*)=0
But in C# Windows application the error occurs.

String st = "select count(*) from treat_info,patient_table where treat_info.pid=patient_table.pid";
OracleCommand cmd = new OracleCommand(st);
cmd.Connection = cn;
OracleDataReader rd = cmd.ExecuteReader();
rd.Read();
int c = rd.GetInt32(0);//error in this line specific cast is not valid
MessageBox.Show(c.ToString());

推荐答案

检查rd.HasRows。如果它为零则没有列零来获取数据,因此它将为null,不是int并且失败,或者抛出一个激活



OR列零没有一个int,也许它是一个浮点数。尝试使用:

int c = Convert.ToInt32(rd.GetValue(0));
check the rd.HasRows. If it is zero then there is no column zero to get the data from so it will be null, not an int and fail, or throw an excpetion

OR column zero doesn't have an int in it, maybe its a float. Try using:
int c = Convert.ToInt32(rd.GetValue(0));


这篇关于错误:特定演员表无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆