一个关于在BCB中用ADO控件向数据库中插入数据的问题
我在BCB 6.0中写了以下代码
ADOQuerySelectManage1->Close();
ADOQuerySelectManage1->SQL->Clear();
ADOQuerySelectManage1->SQL->Add
("insert into 销售单(编号,商品名,货号,客户编号,税价合计,税额,销售数量,单价) values(:id,:name,:code,:custom,:Total,:Tax,:Qty,:Price)");
ADOQuerySelectManage1->Parameters->ParamByName("id")->Value=DBGridSelectManage->Fields[0]->AsString; //DBGridSelectManage是DBGrid组件的名字
ADOQuerySelectManage1->Parameters->ParamByName("name")->Value=DBGridSelectManage->Fields[1]->AsString; //ADOQuerySelectManage1是ADOQuery组件的名字
ADOQuerySelectManage1->Parameters->ParamByName("code")->Value=DBGridSelectManage->Fields[2]->AsString;
ADOQuerySelectManage1->Parameters->ParamByName("custom")->Value=DBGridSelectManage->Fields[3]->AsString;
ADOQuerySelectManage1->Parameters->ParamByName("Total")->Value=DBGridSelectManage->Fields[4]->AsFloat;
ADOQuerySelectManage1->Parameters->ParamByName("Tax")->Value=DBGridSelectManage->Fields[6]->AsFloat;
ADOQuerySelectManage1->Parameters->ParamByName("Qty")->Value=DBGridSelectManage->Fields[7]->AsString;
ADOQuerySelectManage1->Parameters->ParamByName("Price")->Value=DBGridSelectManage->Fields[8]->AsString;
ADOQuerySelectManage1->ExecSQL();
在执行之后发现最后一个字段“单价”中却始终插入不了数据,其他字段都能正常插入,请问各位高手这是怎么回事啊
[解决办法]
ShowMessage(DBGridSelectManage->Fields[8]->AsString);看看值是多少
ADOQuerySelectManage1->Parameters->ParamByName("Price")->Value =123;看能否插进去
[解决办法]
是不是数据类型的问题,Price字段的类型是什么?是不是用AsStirng插入不进去?