c# - how to insert from different inputs -


i trying insert different values table database , retrieve these values different tables , input textbox in windows form etc ..

but syntax of query not correct , want know if there possiblity insert these inputs in 1 query :

     string query4 = @"insert facfin  (nom_pren_rs,trimestre,exercice,nb_factures,prix_total_ht)      values          ('" + textbox1.text + "','" + textbox3.text + "','" + textbox2.text + "',      select cast(count(trimestre) varchar(6)) nb_factures facture           (facture.nom_pren_rs='" + textbox1.text + "'), select cast(sum (cast(prix_vente_ht bigint ))as varchar(15))  facture  (facture.nom_pren_rs='" + textbox1.text + "')    )  "; 

i know there risk of sql injection , know have use parameters wanted test code see if insert , syntax of insert wrong

  • the nb_factures should varchar(6) casted

  • the column prix_vente_ht in table facture varchar casted bigint execute sum , casted sum varchar because prix_total_ht should varchar in table facfin

you cannot add select statement values list, instead select statement keeps aggrigates brings text box values single select statement. if need pull rows multiple tables can union on select section.

string query4 = @"insert facfin (nom_pren_rs,trimestre,exercice,nb_factures,prix_total_ht)  select '" + textbox1.text + "','" + textbox3.text + "','" + textbox2.text + "', cast(count(trimestre) varchar(6)) nb_factures , cast(sum (cast(prix_vente_ht bigint ))as varchar(15)) prix_total_ht facture (facture.nom_pren_rs='" + textbox1.text + "')"; 

the result sql server

insert facfin (nom_pren_rs,trimestre,exercice,nb_factures,prix_total_ht)  select      'text_box_1_value','text_box_3_value','text_box_2_value',      cast(count(trimestre) varchar(6)) nb_factures, cast(sum (cast(prix_vente_ht bigint ))as varchar(15)) prix_total_ht facture (facture.nom_pren_rs='text_box_1_value') 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -