我用SQL Server 2000做的数据库,首先在入库表中插入记录(table1组件),在存货表中查找相应的商品,增加数量
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from store');
query1.SQL.Add('where gno=:gno');
if query1.Fields[0].Value=null then
begin
table1.InsertRecord([gno,gnum,gmodule]);
end
else
begin
table1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);
end
运行有错误,存货表不能插入,请问该如何做?
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from store');
query1.SQL.Add('where gno=:gno');
if query1.Fields[0].Value=null then
begin
table1.InsertRecord([gno,gnum,gmodule]);
end
else
begin
table1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);
end
运行有错误,存货表不能插入,请问该如何做?
解决方案 »
- 查询中Close的位置
- 请熟悉Delphi和VC的大虾帮忙看下
- 高手指教,一个dll的函数调用!
- 有关ADOQuery的Field的Editmask和DisplayFormat的设置!请高手不吝赐教!谢谢!
- 要用delphi开发浏览器,要用拿几个控件,除了用webbrowser之外,还可以用什么呀
- 报表统计
- Access的密码问题
- 一个简单却又非常复杂的问题?向大家求教,在线等待...
- 几个关于Delphi变量类型的问题,我给的分不少吧。帮忙拉一下别沉了。
- delphi 字符串循环截取导入sql 表中
- 高分相送--请大家推荐一下DELPHI中COM,COM+,DCOM多层分布式编程的书,谢谢!
- 急急急~~在线等候!!我用了两个datetimepicker控件~~~~
query1.parambyname('gno').value:=***;
query1.open加到
query1.SQL.Add('where gno=:gno');
后面
query1.Fields[0].Value=null 是一回事,
我估计是因为:1.缺了query1.open
2.你可能把参数gno和query1.Fields[0].Value搞混了,query1.Fields[0].Value
的值是不是指gno的值?如果是的,那table1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);就错了。
关键是不是此问题,Query1的参数gno没赋值,赋完值后还需要打开
with query1 do
begin
Close;
SQL.Clear;
SQL.Add('select gnum from store');
SQL.Add('where gno=:gno');
ParamByName('gno').AsString := '***'
Open;
end; if query1.RecordCount <= 0 then
begin
table1.InsertRecord([gno, gnum, gmodule]);
end
else
begin
table1.SetFields([gno, gnum + query1.FieldByName('gnum').AsFloat, gmodule]);
end
query1.SQL.Clear;
query1.SQL.Add('select gnum from store ');
query1.SQL.Add('where gno=:gno');
query1.parambyname('gno').value:='aaa';
query1.open;if query1.Fields[0].Value=null then
begin
table1.InsertRecord([gno,gnum,gmodule]);
end
else
begin
table1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);
end
query1.SQL.Clear;
query1.SQL.Add('select gnum from store');
//这里下一句的where前没有空格,而且不推荐Query用参数,因为你的Query的SQL本身
//就是动态的,所以可以是这样
//query1.SQL.Add(' where gno='''+String(gno)+'''');
// gno是一个变量,你要在前面申明,因为我看到你后面很多地方用到gnoquery1.SQL.Add('where gno=:gno');
//Query没有Open操作,只有Open操作后,才能得到数据集
if query1.Fields[0].Value=null then
begin
table1.InsertRecord([gno,gnum,gmodule]);
end
else
begin
table1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);
end
//if 和 else后面的begin end 是多余的,因为if else 后面都只有一句话。
//Table1和Query1指定的其实是一个数据集,所以没有必要用到Table1
//最后的数据集没有更新操作,可以这样
//if query1.Fields[0].Value=null then
//Query1.InsertRecord([gno,gnum,gmodule])
//else
//Query1.SetFields([gno,gnum+query1.Fields[0].Value,gmodule]);
//Query1.Post;