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
shouldvarchar(6)
castedthe column
prix_vente_ht
in tablefacture
varchar
castedbigint
execute sum , casted sum varchar becauseprix_total_ht
shouldvarchar
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
Post a Comment