下面的SQL更新将不起作用,但是如果我在员工更新中评论" CIN名称",它将更新。我不明白,因为我在员工搜索过程中已经要求员工姓名,因此该名称变量应与数据分配,但这并没有发生。有人帮我吗?谢谢。
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 Idtt: ";
cin.getline(name,50); // search employee
EXEC SQL SELECT * INTO :salary,:address,:name FROM EMPLOYEES WHERE NAME = :name;
// output empoyee information
cout<<"nCustomer Namett: "<<name;
cout<<"nCustomer contactt: "<<salary;
cout<<"nCustomer statustt: "<<address;
cout<<"nnEnter new value for customer:nn";
// update employee
// cout<<"Customer namett: "; // if I comment out this it will update
// cin.getline(name,50); // if I comment out this it will update
cout<<"Customer salarytt: ";
cin.getline(salary,10);
cout<<"Customer addresstt: ";
cin.getline(address,50);
// check employee name if it initialize
cout<<"nCustomer Namett: "<<name;
EXEC SQL UPDATE EMPLOYEES SET SALARY=:salary, ADDRESS=:address WHERE NAME = :name;
我认为您应该用NAME = 'name'
NAME = :name
而不是使用colon用作:name 在处于条件的位置,在单台引用下添加名称就像我们在sql Query语句中所做的一样。
检查此链接:http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ib.ibm.db2.udb.doc/ad/c0005909.htm>