C#错误转换int类型

时间:2015-01-25 08:19:36

标签: c# postgresql npgsql

我正试图从数据库中获取一些值,但我得到了这个例外:

enter image description here

数据库中“id”列的类型为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)
)

我在C#代码中声明为int

public int Id { get; set; }

1 个答案:

答案 0 :(得分:4)

列是从零开始的,这意味着您需要使用

cat.Id = reader.GetInt32(0);

您还需要将其他列的索引减少1。