我正在尝试通过用户输入同时向2个表添加数据,但是它所做的只是插入第一个表而不是第二个。该代码用于azure sql数据库
String query = "BEGIN TRANSACTION;
INSERT INTO cc_customer (customer_id,customer_first_name,customer_surname,customer_tel_number,customer_cell_number,customer_status,employee_number)
VALUES ('"+id.toString()+"','"+ name.toString()+"','"+ Lname.toString()+"','"+ Telnum.toString()+"','"+Cellnum.toString()+"','"+Status.toString()+"','"+Empnum.toString()+"');
"+"
INSERT INTO cc_customer_address (customer_address_id,customer_building_number,customer_street,customer_suburb,customer_city,customer_zip_code)
VALUES ('"+Cusnum.toString()+"','"+ Cusbuild.toString()+"','"+ Cusstr.toString()+"','"+ Cussub.toString()+"','"+Cuscity.toString()+"','"+Cuszip.toString()+"')COMMIT;";
答案 0 :(得分:0)
这有效!!!!
String query = "BEGIN TRANSACTION INSERT INTO cc_customer(customer_id,customer_first_name,customer_surname,customer_tel_number,customer_cell_number,customer_status,employee_number) VALUES ('"+id.toString()+"','"+name.toString()+"','"+Lname.toString()+"','"+Telnum.toString()+"','"+Cellnum.toString()+"','"+Status.toString()+"','"+Empnum.toString()+"')"+"INSERT INTO cc_customer_address(customer_number,customer_building_number,customer_street,customer_suburb,customer_city,customer_zip_code) VALUES ('"+Cusnum.toString()+"','"+Cusbuild.toString()+"','"+Cusstr.toString()+"','"+Cussub.toString()+"','"+Cuscity.toString()+"','"+Cuszip.toString()+"') COMMIT";