.net 3.5 - insert multipes rows in one request c# -
in visual studio 2008 create smart device net 3.5, please want insert 5000 in 1 request ,for example "insert group_user select 1,5 union select 2,5 ..." dosent work ,i tried directly in sqlmanagment ready inserted exception (le nombre de valeurs dans la liste de sélection de sous-requête est insuffisant. insert many values ) , sorry english :( please need !
public string addgroupuser(list<groupuser> listgroupuser) { string concatenation = ""; (int = 0; < listgroupuser.count; i++) { int nbreenreg = listgroupuser.count; int idgroup = listgroupuser[i].group_id; int iduser = listgroupuser[i].user_id; int dernierelement = nbreenreg - 1; if (i == dernierelement) { concatenation += " select " + iduser + " ," + idgroup + " "; } else { concatenation += " select " + iduser + " ," + idgroup + " union "; } } string requete = "insert group_user " + concatenation; return requete; } internal static int executeupdaten(string requête,sqlceconnection conne) { // on gère les éventuelles exceptions try { // exécute sqlcommand avec requête de mise à jour sqlcecommand sqlcommand = new sqlcecommand(requête, conne); int nblignes = sqlcommand.executenonquery(); return nblignes; } catch (exception e) { return -1; } { connexion.getinstance().closeconnection(); } } executeupdaten(requete);
Comments
Post a Comment