c# - Two Update Statements with One Button Click -


i using sql data adapter in c# windows form , trying run 2 update statements on 2 separate databases 1 button click using same string. keep getting exception error , think second update statement trying use connection first update statement can't figure out. have ideas?

                string resendacct = textbox_resendvisit.text.trim();                  sqlconnection conn1 = new sqlconnection("data source=dbserver1.domain.company.org; initial catalog=db1; user id=username; password=password    ;trusted_connection=false");                  //open sql connection                 conn1.open();                  //create new sqlcommand                 sqlcommand cmd = conn1.createcommand();                 cmd.commandtext =                  "update productiondb1.dbo.date_time  " +                      "set productiondb1.dbo.date_time.sent_datetime = null  " +                  "from productiondb1.dbo.date_time  " +                  "inner join productiondb1.dbo.useridentity  " +                  "on productiondb1.dbo.useridentity.custidentity = productiondb1.dbo.date_time.custidentity  " +                  "where productiondb1.dbo.useridentity.account = @resendtimes";                 cmd.parameters.addwithvalue("@resendtimes", resendacct);                 cmd.executenonquery();                  int norows;                  norows = cmd.executenonquery();                   //this command resends database2 reports!//                  sqlconnection conn2 = new sqlconnection("data source=dbserv2.domain.company.org; initial catalog=db2; integrated security=true");                  //open sql connection                 conn2.open();                  //create new sql command                 sqlcommand cmd1 = conn2.createcommand();                 cmd.commandtext =                     "update productiondb2.dbo.date_time  " +                         "set productiondb2.dbo.date_time.timedone = null  " +                     "from productiondb2.dbo.date_time  " +                     "inner join productiondb2.dbo.custidentity  " +                     "on productiondb2.dbo.custidentity.id = productiondb2.dbo.date_time.custencounter_id  " +                     "inner join productiondb2.dbo.custencounter  " +                     "on productiondb2.dbo.custencounter.id = productiondb2.dbo.custidentity.custencounter_id  " +                     "where productiondb2.dbo.custencounter.accountnumber = @resendtimes";                 cmd.parameters.addwithvalue("@resendtimes", resendacct);                 cmd.executenonquery();                  int norows1;                  norows1 = cmd1.executenonquery();                 //close sqlconnections                 conn1.close();                 conn2.close(); 

your second command being assigned first command variable created. command using first connection. check cmd , cmd1. think second sql statement should assigned cmd1 instead of cmd.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -