我一直在尋找,但我不知道如何,我是新來的,所以如果有人可以幫助我,我會感激!插入到哪裏使用Postgres和C#
問題是我需要插入一個名爲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";
所有的ID除了idFarmaco是其他表的Foreing鍵。那些表只有2列,即id和one。在我的程序代碼中,這些名稱列在組合框中。我需要的是插入到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中的所有文本。
的更遠,我得到的是這樣的:
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" = '......
nop,cuz在組合框我有名字,而不是id。例如。我的表格Presentacion有一個idPrePreacion列和一個NamePresentacion列。並且由於它們被排序,所以SelectedIndex和id之間沒有對應關係。我需要在表中比較,所以我可以得到該名稱的ID – dbncourt 2012-02-25 06:27:29