SqlDataAdapter.Fill throws me an IndexOutOfRangeException

U

Uri Dor

for some reason, a specific database state gives me an
IndexOutOfRangeException when I call SqlDataAdapter.Fill (in several
cases the same code doesn't throw the exception)

the SELECT is:
SELECT Bank_sec_code, Dt, Par_val, Rate, Rate_nis FROM dbo.Common_rates
WHERE (Dt = @dt)

I supply a valid @dt parameter

when I run the query from query analyzer I get a valid, nonempty result.

when I script the table I get:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Common_rates]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[Common_rates]
GO

CREATE TABLE [dbo].[Common_rates] (
[Bank_sec_code] [int] NOT NULL ,
[Dt] [datetime] NOT NULL ,
[Par_val] [float] NOT NULL ,
[Rate] [float] NOT NULL ,
[Rate_nis] [float] NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Common_rates] WITH NOCHECK ADD
CONSTRAINT [PK_Common_rates] PRIMARY KEY CLUSTERED
(
[Bank_sec_code],
[Dt]
) ON [PRIMARY]
GO


Any ideas?
 
B

Bernie Yaeger

Hi Uri,

Index out of range is a strange error for the fill failure. Are you certain
of the parameter value? Try running the fill with 'where dt = '1234' or
whatever. Do this time and again. If you never experience the error, it
almost have to be the parameter value.

HTH,

Bernie Yaeger
 
M

Miha Markic [MVP C#]

Hi Uri,

Could it be that you fill a table where at least one DataColumn.DataType has
less range then required?
 
V

Val Mazur

Hi,

You showed us what you have on a server side, but actually did not show the
code, which throws the exception. What is this code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top