2012-02-25 44 views
1

我一直在尋找,但我不知道如何,我是新來的,所以如果有人可以幫助我,我會感激!插入到哪裏使用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" = '...... 

回答

1

你是否在尋找:

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

nop,cuz在組合框我有名字,而不是id。例如。我的表格Presentacion有一個idPrePreacion列和一個NamePresentacion列。並且由於它們被排序,所以SelectedIndex和id之間沒有對應關係。我需要在表中比較,所以我可以得到該名稱的ID – dbncourt 2012-02-25 06:27:29

0

假設你正在使用的WinForms項目:你可以提供一個組合框數據源,並設置顯示器部件和數據存儲器。顯示成員是在組合框中顯示的成員,數據成員是在場景後面使用的與所選顯示成員相對應的成員。在你的情況下:創建一個數據源與表中的信息Presentacion並將idPresentacion設置爲datamember和NamePresentacion作爲顯示成員

+0

Nah,現在我只是要得到每一個ID,並做一個簡單的插入,但我知道應該有一種方法來做,只是插入,比較並獲取每個ID的名稱。 – dbncourt 2012-02-26 02:00:25