I've been searching but I don't know how, and I'm new in this, so if someone can help me, I'll be thankful!
The problem is that i need to insert into a table called Farmaco
a lot of things.
My table 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";
All the id's except the idFarmaco are Foreing Keys of others tables. Those tables just have 2 columns, the id one and the name one. In my program code, those names are listed in comboboxes. What i need is to insert into farmaco all that data selected, and the names, etc.
For example
I want to insert in the table this "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)
all those id are stored in the database and im filling those with a query, sorted alphabetically, but now i dont know how to make a query so i can insert the respectives ids with all the text's in the texboxes.
The farther i've get is this:
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" = '......