using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; using system.data.sqlclient; using system.data.sqltypes;
…public void sptransaction(int partid, int numbermoved, int siteid) { // create and open the connection. sqlconnection conn = new sqlconnection(); string connstring = "server=sqlinstance;database=test;" + "integrated security=sspi"; conn.connectionstring = connstring; conn.open();
// create the commands and related parameters. // cmddebit debits inventory from the warehouseinventory // table by calling the debitwarehouseinventory // stored procedure. sqlcommand cmddebit = new sqlcommand("debitwarehouseinventory", conn); cmddebit.commandtype = commandtype.storedprocedure; cmddebit.parameters.add("@partid", sqldbtype.int, 0, "partid"); cmddebit.parameters["@partid"].direction = parameterdirection.input; cmddebit.parameters.add("@debit", sqldbtype.int, 0, "quantity"); cmddebit.parameters["@debit"].direction = parameterdirection.input;
// cmdcredit adds inventory to the siteinventory // table by calling the creditsiteinventory // stored procedure. sqlcommand cmdcredit = new sqlcommand("creditsiteinventory", conn); cmdcredit.commandtype = commandtype.storedprocedure; cmdcredit.parameters.add("@partid", sqldbtype.int, 0, "partid"); cmdcredit.parameters["@partid"].direction = parameterdirection.input; cmdcredit.parameters.add ("@credit", sqldbtype.int, 0, "quantity"); cmdcredit.parameters["@credit"].direction = parameterdirection.input; cmdcredit.parameters.add("@siteid", sqldbtype.int, 0, "siteid"); cmdcredit.parameters["@siteid"].direction = parameterdirection.input;
// begin the transaction and enlist the commands. sqltransaction tran = conn.begintransaction(); cmddebit.transaction = tran; cmdcredit.transaction = tran;