我在adp.Fill中遇到错误(ds,“Products”);说
“'='附近的语法不正确。
我该如何解决?
这是我的代码:
/* Using a pipe to send data from a parent to a child process
*/
#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <string.h>
using namespace std;
int main(int argc, char *argv[ ]) {
int f_des[2];
int f_des2[2];
static char message[5];
if (argc != 2) {
cerr << "Usage: " << *argv << " message\n";
return 1;
}
if (pipe(f_des) == -1 || pipe(f_des2) == -1) { // generate the pipe
perror("Pipe");
return 2;
}
switch (fork( )) {
case -1:
perror("Fork");
return 3;
case 0: // In the child
close(f_des[1]);
if (read(f_des[0], message, BUFSIZ) != -1) {
cout << "Message received by child: [" << message
<< "]" << endl;
cout.flush();
} else {
perror("Read");
return 4;
}
close(f_des[0]);
close(f_des2[0]);
if (write(f_des[1], argv[2], strlen(argv[2])) != -1) {
cout << "Message sent by child : [" <<
argv[1] << "]" << endl;
cout.flush();
} else {
perror("Write");
return 5;
}
break;
default: // In the Parent
close(f_des[0]);
if (write(f_des[1], argv[1], strlen(argv[1])) != -1) {
cout << "Message sent by parent : [" <<
argv[1] << "]" << endl;
cout.flush();
} else {
perror("Write");
return 6;
}
close(f_des[0]);
close(f_des2[0]);
if (read(f_des[0], message, BUFSIZ) != -1) {
cout << "Message received by parent: [" << message
<< "]" << endl;
cout.flush();
} else {
perror("Read");
return 7;
}
}
return 0;
}
答案 0 :(得分:2)
那边有语法错误:
快速修复:
string cmdstr = "SELECT ProductID, ProductName, CategoryCode, PurchasePrice, " +
" SellingPrice, Description, Quantity, ProdStatusCode FROM Products" +
" WHERE ProductID = '" + productID + "'"
智能修复:
给定的代码将为sqlInjection打开一扇大门。所以我更喜欢你使用参数化查询代替:
string cmdstr = "SELECT ProductID, ProductName, CategoryCode, PurchasePrice, " +
" SellingPrice, Description, Quantity, ProdStatusCode FROM Products" +
" WHERE ProductID =@productID"
SqlCommand cmd = new SqlCommand(cmdstr, connection);
cmd.Parameters.Add("@productID", SqlDbType.VarChar).Value = productID;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds, "Products");