Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 VB.Net SQL Exception for Integer Values

Author  Topic 

JustDave
Starting Member

2 Posts

Posted - 2004-12-01 : 14:40:59
I am getting the following exception:

quote:
An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Additional information: Specified cast is not valid.



I am getting this error using:

   theRange.Value = rdrReportData.GetSqlInt16(x)


to retrieve an integer value From the SQL Statement:

Select Count(PatientNumber) From PatientBilling


theRange is an excel cell, and rdrReportData is a SQLClient.SQLDataReader

I have also tried GetSQLInt32,GetSQLInt64 (which works for data type bigint), GetInt16, GetInt32, GetInt64, GetSingle, GetSQLSingle, GetDouble, GetSQLDouble, and GetValue.

This happens for me with any Int value returned, wheter a field of type int or an expression with an int result.

Any clues where to go/What to do would be appreciated.

Thank you!


JustDave

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-12-01 : 14:53:45
Maybe try:
theRange.Value = rdrReportData.GetSqlInt16(x).Value
what is the type of theRange.Value ?

rdrReportData.GetSqlInt16(x).Value -- this is int (Int32)
rdrReportData.GetSqlInt16(x) -- this is SqlInt32


rockmoose
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-12-01 : 15:09:53
Perhaps the value you are trying to convert is null?

Try checking the value with Convert.DbNULL or use the method Convert.IsDbNull

Dustin Michaels
Go to Top of Page
   

- Advertisement -