qry:=TAdoQuery.Create(nil);
qry.Connection :=conn;
qry.Connection.BeginTrans;
for i:=0 to TFilePathList.count-1do
begin
strm.LoadFromFile(TFilePathList[i]);
qry.SQL.add( 'insert into test(pic) values (:pic)');
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
end;
qry.ExecSQL;
qry.Connection.CommitTrans;
为什么上面总是存储最后一条的数据?
上面的存储若使用事务(下面是参考sqlserver事务),红色字体是我使用事务,还是不行,各位大神有没有思路?for i:=1 to 10000 do
begin
Name:= QuotedStr('easyboot'+InttoStr(i));
SqlStr:=SqlStr+ Format(' insert into MyTest (Name) values (%s) ',[Name]);
end;
ADOConnection1.Open;
ADOConnection1.BeginTrans;
ADOCommand1.CommandText:=SqlStr;
ADOCommand1.Execute();
ADOConnection1.CommitTrans;
qry.Connection :=conn;
qry.Connection.BeginTrans;
for i:=0 to TFilePathList.count-1do
begin
strm.LoadFromFile(TFilePathList[i]);
qry.SQL.add( 'insert into test(pic) values (:pic)');
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
end;
qry.ExecSQL;
qry.Connection.CommitTrans;
为什么上面总是存储最后一条的数据?
上面的存储若使用事务(下面是参考sqlserver事务),红色字体是我使用事务,还是不行,各位大神有没有思路?for i:=1 to 10000 do
begin
Name:= QuotedStr('easyboot'+InttoStr(i));
SqlStr:=SqlStr+ Format(' insert into MyTest (Name) values (%s) ',[Name]);
end;
ADOConnection1.Open;
ADOConnection1.BeginTrans;
ADOCommand1.CommandText:=SqlStr;
ADOCommand1.Execute();
ADOConnection1.CommitTrans;
解决方案 »
- 多从机485接受信号延迟问题
- delphi窗体停靠后,不能拖出窗体
- 怎样写一个unit1,把一些函数定义为公共函数,在另一个UNIT中调用?
- sqlserver中的函数newid()如何作为参数传给存储过程呢???
- 巨奇怪的问题! adoCmd.CommandText:='UPdate student set stdno=:stdno';
- 编译指令 这个{$DEFINE}{$ENDIF}怎么用啊,不知道前辈可否详细介绍一下?
- 談談**回調函數**
- 请问如何将ADOQuery的查询数据导出到TXT文本文件?在线等待!(内有示范数据格式)
- 有关于CRYSTAL REPORTS的几个菜鸟问题!!
- 100分,多个线程把搜集的数据各自生成txt文件,只启动一个线程添加到数据库,请指教?
- invalid pointer operation, DELPHI 问题
- delphi函数作为C++回调函数使用报错
放循环里面!你放外面当然总是最后一个了!
放循环里面!
那qry.SQL.add( 'insert into test(pic) values (:pic)'); 不用ADD了吧,
qry.SQL.text := 'insert into test(pic) values (:pic)';,好似效率没有什么提升。
你要不放里面根本就不对,而不是效率问题,至于你是用ADD还是Text这是另外的问题!个人感觉小数据量这两种没什么区别。
for i:=0 to TFilePathList.count-1do
begin
strm.LoadFromFile(TFilePathList[i]);
qry.SQL.add( 'insert into test(pic) values (:pic)');
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
qry.ExecSQL;
end;
qry.Connection.CommitTrans;
比较好的事务处理,代码如下: try
ADOCon.BeginTrans; // 开始事务
for i:=0 to n do
begin
SQL:='InSetrt.......'; // 生成SQL语句
ADOCon.Execute(SQL); // 放入执行队列
end;
ADOCon.CommitTrans; // 提交事务
Result:=True;
except
on E:Exception do
begin
ADOCon.RollbackTrans; // 事务回滚
err:=E.Message;
end;
end;
qry.Connection :=conn;for i:=0 to TFilePathList.count-1do
begin
strm.LoadFromFile(TFilePathList[i]);
qry.SQL.add( 'insert into test(pic) values (:pic)');
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
end;
//其实,事务在这里有意义更大的吧!
//让服务器去响应你的事务,分配资源,一个事务的体积也不建议太大
//觉得这样的效率会不会更高点
qry.Connection.BeginTrans;
qry.ExecSQL;
qry.Connection.CommitTrans;
begin
strm.LoadFromFile(TFilePathList[i]);
qry.SQL.add( 'insert into test(pic) values (:pic)');
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
//上面写错了,修改一下
//其实,事务在这里有意义更大的吧!
//让服务器去响应你的事务,分配资源,一个事务的体积也不建议太大
//觉得这样的效率会不会更高点
qry.Connection.BeginTrans;
qry.ExecSQL;
qry.Connection.CommitTrans;
end;