Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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());
Posted
Updated 31-Jul-15 9:55am
v2

1 solution

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));
 
Share this answer
 
Comments
Sunil Kumar Das 1-Aug-15 0:02am    
thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900