0

下面的 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;
4

1 回答 1

0

I think you should replace NAME = :name with NAME = 'name'

Instead of using colon as :name in where condition, put name under single quotes just like we do in SQL query statement.

Check this link: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/c0005909.htm

于 2013-09-14T13:33:43.110 回答