Table is read Only
此代码的功能:对数据库进行数据的写入,首先判断数据库中有没有要插入的sn(sn是主键),如果有就执行update语句,如果没有就新插入这个sn记录。但是我用以下代码执行的时候update语句可以执行,为什么到了insert语句的时候就报错,提示: cannot perform this operation on closed dataset;请各位赐教!谢谢!
Form2->Query1->Close() ;
for(int i=0; i <nbP; i++)
{
Form2->Query1->RequestLive = true ;
ShowMessage("start");
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("select * from label_demo ;") ;
Form2->Query1->Open() ;
Form2->Query1->First() ;
int p_qty ;
while(!Form2->Query1->Eof)
{
ShowMessage("while start");
Form2->Query1->Edit() ;
if(Form2->Query1->FieldByName("sn")->AsInteger == snLong)
{
p_qty = Form2->Query1->FieldByName("p_qty")->AsInteger + 1 ;
ShowMessage("start update");
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("update label_demo set p_qty = :p_qty where sn = :sn ;") ;
Form2->Query1->ParamByName("p_qty")->AsInteger = p_qty ;
Form2->Query1->ParamByName("sn")->AsInteger = snLong ;
Form2->Query1->ExecSQL() ;
ShowMessage(" find it ");
}
Form2->Query1->Next() ;
}
//Form2->Query1->Open() ;
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("insert into label_demo (sn,pc,mac1,mac2) values (:sn,:pc,:mac1,:mac2)") ;
Form2->Query1->Params->ParamByName("sn")->AsInteger = snLong ;
Form2->Query1->Params->ParamByName("pc")->AsString = Form2->pcVar->Text.c_str() ;
Form2->Query1->Params->ParamByName("mac1")->AsInteger = mac1Long ;
Form2->Query1->Params->ParamByName("mac2")->AsInteger = mac2Long ;
Form2->Query1->ExecSQL() ;
snLong += 1 ;
mac1Long += 8 ;
mac2Long += 8 ;
}
Form2->Query1->Close() ;
for(int i=0; i <nbP; i++)
{
Form2->Query1->RequestLive = true ;
ShowMessage("start");
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("select * from label_demo ;") ;
Form2->Query1->Open() ;
Form2->Query1->First() ;
int p_qty ;
while(!Form2->Query1->Eof)
{
ShowMessage("while start");
Form2->Query1->Edit() ;
if(Form2->Query1->FieldByName("sn")->AsInteger == snLong)
{
p_qty = Form2->Query1->FieldByName("p_qty")->AsInteger + 1 ;
ShowMessage("start update");
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("update label_demo set p_qty = :p_qty where sn = :sn ;") ;
Form2->Query1->ParamByName("p_qty")->AsInteger = p_qty ;
Form2->Query1->ParamByName("sn")->AsInteger = snLong ;
Form2->Query1->ExecSQL() ;
ShowMessage(" find it ");
}
Form2->Query1->Next() ;
}
//Form2->Query1->Open() ;
Form2->Query1->SQL->Clear() ;
Form2->Query1->SQL->Add("insert into label_demo (sn,pc,mac1,mac2) values (:sn,:pc,:mac1,:mac2)") ;
Form2->Query1->Params->ParamByName("sn")->AsInteger = snLong ;
Form2->Query1->Params->ParamByName("pc")->AsString = Form2->pcVar->Text.c_str() ;
Form2->Query1->Params->ParamByName("mac1")->AsInteger = mac1Long ;
Form2->Query1->Params->ParamByName("mac2")->AsInteger = mac2Long ;
Form2->Query1->ExecSQL() ;
snLong += 1 ;
mac1Long += 8 ;
mac2Long += 8 ;
}
...全文
相关推荐
mysql中Table is read only的解决方法小结
**权限问题**: - 当数据库表的文件权限不足时,可能会导致“Table is read only”的错误。
Linux下MySql 1036 错误码解决(1036: Table ‘xxxx’ is read only)
在Linux环境下,当你遇到MySQL错误1036(Table 'xxxx' is read only),这通常表示某个表或整个数据库被设置为只读模式,不允许写入操作。这种情况可能出现在以下场景中:在
Linux下MySql 1036 错误码解决(1036: Table 'xxxx' is read only)
在Linux环境下操作MySQL数据库时,有时会遇到错误码1036,提示“Table 'xxxx' is read only”。
设置SQLServer数据库中某些表为只读的多种方法分享
is read only.', 16, 1) ROLLBACK TRANSACTION END ```3.
ABAP基本语法学习关键语句的写法[借鉴].pdf
] [READ-ONLY].其中,itab 是内表的名称,tabkind 是内表的种类,可以是 STANDARD TABLE、SORTED TABLE 或 HASHED TABLE。


