SlimenTN
SlimenTN

Reputation: 3564

C# error casting int type

I'm trying to get some values from database but I got this exception:

enter image description here

the type of the column "id" in database is Ineger:

CREATE TABLE crs_categorie_taux
(
  id serial NOT NULL,
  designation character varying(225),
  taux double precision,
  CONSTRAINT crs_categorie_taux_pkey PRIMARY KEY (id)
)

and I declare it as int in my C# code:

public int Id { get; set; }

Upvotes: 0

Views: 182

Answers (1)

krivtom
krivtom

Reputation: 24916

The columns are zero-based, this means you need to use

cat.Id = reader.GetInt32(0);

You also need to decrease indexes for other columns by 1 as well.

Upvotes: 4

Related Questions