下面的 sql 更新将不起作用,但如果我在员工更新时注释掉“cin name”,它将更新。我不明白,因为我已经在员工搜索期间询问了员工姓名,因此应该为 name 变量分配数据,但这并没有发生。有人帮我吗?谢谢你。
EXEC SQL BEGIN DECLARE SECTION;
//int customer_id,cu_id;
char salary[10],address[50];
char name[50];
EXEC SQL END DECLARE SECTION;
fnConnectDB();
cout<<"Customer Id\t\t: ";
cin.getline(name,50); // search employee
EXEC SQL SELECT * INTO :salary,:address,:name FROM EMPLOYEES WHERE NAME = :name;
// output empoyee information
cout<<"\nCustomer Name\t\t: "<<name;
cout<<"\nCustomer contact\t: "<<salary;
cout<<"\nCustomer status\t\t: "<<address;
cout<<"\n\nEnter new value for customer:\n\n";
// update employee
// cout<<"Customer name\t\t: "; // if I comment out this it will update
// cin.getline(name,50); // if I comment out this it will update
cout<<"Customer salary\t\t: ";
cin.getline(salary,10);
cout<<"Customer address\t\t: ";
cin.getline(address,50);
// check employee name if it initialize
cout<<"\nCustomer Name\t\t: "<<name;
EXEC SQL UPDATE EMPLOYEES SET SALARY=:salary, ADDRESS=:address WHERE NAME = :name;