以下代码mysql执行报错,是哪里出错了,怎么修正 String add_sql = "INSERT INTO detail(" "name," "width," "height," "quantity," "material," "thickness," "stiffiness," "density," "materialUnitPrice," "materialSize,pcs," "columnNum," "rowNum," "machineUnitPrice," "sampleCost," "shearPlate," "levelling," "freight," "others," "costUnitPrice," "quotePrice," "shearPlateAmount," "standbyPlate," "actualWeight," "sales," "estimateCost," "futureProfit," "createtime) " "VALUES('$v_name'," "'$v_width'," "'$v_height'," "'$v_quantity'," "'$v_material'," "'$v_thickness'," "'$v_stiffiness'," "'$v_density'," "'$v_materialUnitPrice'," "'$v_materialSize'," "'$v_pcs'," "'$v_columnNum'," "'$v_rowNum'," "'$v_machineUnitPrice'," "'$v_sampleCost'," "'$v_shearPlate'," "'$v_levelling'," "'$v_freight'," "'$v_others'," "'$v_costUnitPrice'," "'$v_quotePrice'," "'$v_shearPlateAmount'," "'$v_standbyPlate'," "'$v_actualWeight'," "'$v_sales'," "'$v_estimateCost'," "'$v_futureProfit'," "'$v_createtime')"; await conn.transaction((tran) async{ await tran.rawInsert(add_sql); print("保存成功!");
时间: 2023-07-05 15:19:02 浏览: 134
在MySQL数据库中使用C执行SQL语句的方法
这段代码中的问题在于SQL语句中的部分字符串没有用单引号括起来,导致SQL语句格式错误。以下是修正后的代码:
```
String add_sql = "INSERT INTO detail("
"name,"
"width,"
"height,"
"quantity,"
"material,"
"thickness,"
"stiffiness,"
"density,"
"materialUnitPrice,"
"materialSize,pcs,"
"columnNum,"
"rowNum,"
"machineUnitPrice,"
"sampleCost,"
"shearPlate,"
"levelling,"
"freight,"
"others,"
"costUnitPrice,"
"quotePrice,"
"shearPlateAmount,"
"standbyPlate,"
"actualWeight,"
"sales,"
"estimateCost,"
"futureProfit,"
"createtime) "
"VALUES('$v_name',"
"'$v_width',"
"'$v_height',"
"'$v_quantity',"
"'$v_material',"
"'$v_thickness',"
"'$v_stiffiness',"
"'$v_density',"
"'$v_materialUnitPrice',"
"'$v_materialSize','$v_pcs',"
"'$v_columnNum',"
"'$v_rowNum',"
"'$v_machineUnitPrice',"
"'$v_sampleCost',"
"'$v_shearPlate',"
"'$v_levelling',"
"'$v_freight',"
"'$v_others',"
"'$v_costUnitPrice',"
"'$v_quotePrice',"
"'$v_shearPlateAmount',"
"'$v_standbyPlate',"
"'$v_actualWeight',"
"'$v_sales',"
"'$v_estimateCost',"
"'$v_futureProfit',"
"'$v_createtime')";
await conn.transaction((tran) async{
await tran.rawInsert(add_sql);
print("保存成功!");
});
```
修正后的代码中,SQL语句中的每个字符串都被单引号括起来了。另外,`materialSize,pcs`中间的逗号也被修正为了一个单引号。
阅读全文