gpt4 book ai didi

c# - 使用 Postgres 和 C# 插入到哪里

转载 作者:行者123 更新时间:2023-11-29 13:36:32 25 4
gpt4 key购买 nike

我一直在寻找,但我不知道如何,我是新手,所以如果有人能帮助我,我将不胜感激!

问题是我需要在一个名为 Farmaco 的表中插入很多东西。我的表 Farmaco:

CREATE TABLE "Farmaco" (
"idFarmaco" bigint NOT NULL DEFAULT nextval('idfarmaco'::regclass),
"Nombre" character varying(100) NOT NULL,
"PrecioReferencial" real NOT NULL,
"Descripcion" character varying(500),
"Stock" integer NOT NULL,
"MinStock" integer,
"MaxStock" integer,
"idPresentacion" integer NOT NULL,
"idTipo" integer NOT NULL,
"idUnidadDeManejo" integer NOT NULL,
"idMarca" integer NOT NULL,
CONSTRAINT "PKFarmaco" PRIMARY KEY ("idFarmaco" ),
CONSTRAINT "FKFarmaco_Marca" FOREIGN KEY ("idMarca")
REFERENCES "Marca" ("idMarca") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "FKFarmaco_Presentacion" FOREIGN KEY ("idPresentacion")
REFERENCES "Presentacion" ("idPresentacion") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "FKFarmaco_Tipo" FOREIGN KEY ("idTipo")
REFERENCES "Tipo" ("idTipo") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "FKFarmaco_UnidadDeManejo" FOREIGN KEY ("idUnidadDeManejo")
REFERENCES "UnidadDeManejo" ("idUnidadDeManejo") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE "Farmaco"
OWNER TO "Daniel";

除了 idFarmaco 之外的所有 id 都是其他表的 Foreing Keys。这些表只有 2 列,id 一列和名称一列。在我的程序代码中,这些名称列在组合框中。我需要的是将所有选定的数据以及名称等插入到 farmaco 中。

例如

我想在表格中插入这个“Farmaco”:

"Nombre": Stack (textbox)
"PrecioReferencial": 150.30 (textbox)
"Descripcion" : spensive (textbox)
"Stock" : 20 (textbox)
"MinStock" : 10 (textbox)
"MaxStock" : 50 (textbox)
"idPresentacion" : Caja (this was selected in the combobox)
"idTipo" : Medicina (this was selected in the combobox)
"idUnidadDeManejo": Unidad (this was selected in the combobox)
"idMarca" : Bayer (this was selected in the combobox)

所有这些 id 都存储在数据库中,我用查询填充它们,按字母顺序排序,但现在我不知道如何进行查询,所以我可以在 texboxes 中插入带有所有文本的相应 id。

我得到的更远的是:

Insert into "Farmaco"
Select "idPresentacion", "idTipo", "idMarca", "idUnidadDeManejo"
From "Presentacion", "Tipo", "Marca", "UnidadDeManejo"
Where "NombrePresentacion" = 'Here should be the text in the ComboBox cbPresentacion.SelectedItem.ToString()' AND "NombreTipo" = '......

最佳答案

您在寻找:

insert into "Farmaco" ("idPresentacion", "idTipo", "idMarca", "idUnidadDeManejo")
values ( cbPresentacion.SelectedItem.ToString(), ... )

关于c# - 使用 Postgres 和 C# 插入到哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9441403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com