这个问题在Delphibbs中也有提问。 http://www.delphibbs.com/delphibbs/dispq.asp?lid=2376172代码在那边也有: if (Sender as TBitBtn).Name='btn_Post' then begin //检查数据是否完整 if not CheckField() then exit; if ed_Long.Text='' then ed_Long.Field.Value:=0; if ed_Width.Text='' then ed_Width.Field.Value:=0; if ed_Height.Text='' then ed_Height.Field.Value:=0; if ed_PackingLong.Text='' then ed_PackingLong.Field.Value:=0; if ed_PackingWidth.Text='' then ed_PackingWidth.Field.Value:=0; if ed_PackingHeight.Text='' then ed_PackingHeight.Field.Value:=0; if ed_PackingVol.Text='' then ed_PackingVol.Field.Value:=0; if ed_PackingOuterBoxQuantity.Text='' then ed_PackingOuterBoxQuantity.Field.Value:=0; if ed_PackingInnerBoxCount.Text='' then ed_PackingInnerBoxCount.Field.Value:=0; if ed_GrossWeight.Text='' then ed_GrossWeight.Field.Value:=0; if ed_NetWeight.Text='' then ed_NetWeight.Field.Value:=0; //这里。 ds_DataSource.DataSet.Post(); end;
上面贴出来的只是Post代码。 //编辑 if (Sender as TBitBtn).Name='btn_Edit' then begin ds_DataSource.DataSet.Edit(); pg_Page.ActivePageIndex:=0; cb_NameCN.SelectAll(); cb_NameCN.SetFocus(); end;procedure TfrmProducts.aq_ADOQueryAfterEdit(DataSet: TDataSet); begin ed_OperatorEx.Field.Value:=g_sOperator; ed_ModifyDate.Field.Value:=Now(); end;
好像也没有啊。 /****** Object: Table [dbo].[Products] Script Date: 2003-12-26 12:58:33 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Products] GO/****** Object: Table [dbo].[Products] Script Date: 2003-12-26 12:58:35 ******/ CREATE TABLE [dbo].[Products] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [proNo] [varchar] (50) NOT NULL , [proCode] [varchar] (50) NULL , [proNameCn] [varchar] (100) NULL , [proNameEn] [varchar] (100) NULL , [proManufacturerNo] [varchar] (20) NULL , [proManufacturerProductNo] [varchar] (50) NULL , [proKindNo] [varchar] (20) NULL , [proPackageCn] [varchar] (100) NULL , [proPackageEn] [varchar] (100) NULL , [proPrice] [money] NULL , [proLong] [float] NULL , [proWidth] [float] NULL , [proHeight] [float] NULL , [proPackingLong] [float] NULL , [proPackingWidth] [float] NULL , [proPackingHeight] [float] NULL , [proPackingVol] [float] NULL , [proPackingInnerBoxCount] [int] NULL , [proPackingOuterBoxQuantity] [int] NULL , [proGrossWeight] [float] NULL , [proNetWeight] [float] NULL , [proDescription] [varchar] (255) NULL , [proRe] [ntext] NULL , [AddDate] [smalldatetime] NULL , [ModifyDate] [smalldatetime] NULL , [Operator] [varchar] (50) NULL , [OperatorEx] [varchar] (50) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GOALTER TABLE [dbo].[Products] WITH NOCHECK ADD CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED ( [proNo] ) ON [PRIMARY] GO CREATE INDEX [IX_Products] ON [dbo].[Products]([ID]) ON [PRIMARY] GO CREATE INDEX [IX_Products_1] ON [dbo].[Products]([proNo]) ON [PRIMARY] GO CREATE INDEX [IX_Products_2] ON [dbo].[Products]([proCode]) ON [PRIMARY] GO CREATE INDEX [IX_Products_3] ON [dbo].[Products]([proNameCn]) ON [PRIMARY] GO CREATE INDEX [IX_Products_4] ON [dbo].[Products]([proNameEn]) ON [PRIMARY] GO CREATE INDEX [IX_Products_5] ON [dbo].[Products]([proManufacturerNo]) ON [PRIMARY] GO CREATE INDEX [IX_Products_6] ON [dbo].[Products]([proManufacturerProductNo]) ON [PRIMARY] GO CREATE INDEX [IX_Products_7] ON [dbo].[Products]([proKindNo]) ON [PRIMARY] GO CREATE INDEX [IX_Products_8] ON [dbo].[Products]([proPackageCn]) ON [PRIMARY] GO CREATE INDEX [IX_Products_9] ON [dbo].[Products]([proPackageEn]) ON [PRIMARY] GO CREATE INDEX [IX_Products_10] ON [dbo].[Products]([proPrice]) ON [PRIMARY] GO CREATE INDEX [IX_Products_11] ON [dbo].[Products]([proLong]) ON [PRIMARY] GO CREATE INDEX [IX_Products_12] ON [dbo].[Products]([proWidth]) ON [PRIMARY] GO CREATE INDEX [IX_Products_13] ON [dbo].[Products]([proHeight]) ON [PRIMARY] GO CREATE INDEX [IX_Products_14] ON [dbo].[Products]([proPackingLong]) ON [PRIMARY] GO CREATE INDEX [IX_Products_15] ON [dbo].[Products]([proPackingVol]) ON [PRIMARY] GO CREATE INDEX [IX_Products_16] ON [dbo].[Products]([proPackingInnerBoxCount]) ON [PRIMARY] GO CREATE INDEX [IX_Products_17] ON [dbo].[Products]([proPackingOuterBoxQuantity]) ON [PRIMARY] GO CREATE INDEX [IX_Products_18] ON [dbo].[Products]([proGrossWeight]) ON [PRIMARY] GO CREATE INDEX [IX_Products_19] ON [dbo].[Products]([proNetWeight]) ON [PRIMARY] GO CREATE INDEX [IX_Products_20] ON [dbo].[Products]([proDescription]) ON [PRIMARY] GO CREATE INDEX [IX_Products_21] ON [dbo].[Products]([AddDate]) ON [PRIMARY] GO CREATE INDEX [IX_Products_22] ON [dbo].[Products]([ModifyDate]) ON [PRIMARY] GO CREATE INDEX [IX_Products_23] ON [dbo].[Products]([Operator]) ON [PRIMARY] GO CREATE INDEX [IX_Products_24] ON [dbo].[Products]([OperatorEx]) ON [PRIMARY] GO
以前也遇到过,但主要是默认值的问题。但这次是
“所有的表都有一个ID,自增的。没有默认值。”所以才不知是哪里的问题,只能看看哪个有过这样的经验,指点一下了。第一次Post没问题,再编辑再Post就出现了。
Access和SQL Server的问题上。转移视线吧
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2376172代码在那边也有:
if (Sender as TBitBtn).Name='btn_Post' then
begin
//检查数据是否完整
if not CheckField() then exit; if ed_Long.Text='' then ed_Long.Field.Value:=0;
if ed_Width.Text='' then ed_Width.Field.Value:=0;
if ed_Height.Text='' then ed_Height.Field.Value:=0;
if ed_PackingLong.Text='' then ed_PackingLong.Field.Value:=0;
if ed_PackingWidth.Text='' then ed_PackingWidth.Field.Value:=0;
if ed_PackingHeight.Text='' then ed_PackingHeight.Field.Value:=0;
if ed_PackingVol.Text='' then ed_PackingVol.Field.Value:=0;
if ed_PackingOuterBoxQuantity.Text='' then ed_PackingOuterBoxQuantity.Field.Value:=0;
if ed_PackingInnerBoxCount.Text='' then ed_PackingInnerBoxCount.Field.Value:=0;
if ed_GrossWeight.Text='' then ed_GrossWeight.Field.Value:=0;
if ed_NetWeight.Text='' then ed_NetWeight.Field.Value:=0; //这里。
ds_DataSource.DataSet.Post();
end;
AdoXXX.Append 或 Edit???
然後, 如果 ed_XXXX裹面有數值, 那就不會給字段付值了???
if (Sender as TBitBtn).Name='btn_Edit' then
begin
ds_DataSource.DataSet.Edit();
pg_Page.ActivePageIndex:=0;
cb_NameCN.SelectAll();
cb_NameCN.SetFocus();
end;procedure TfrmProducts.aq_ADOQueryAfterEdit(DataSet: TDataSet);
begin
ed_OperatorEx.Field.Value:=g_sOperator;
ed_ModifyDate.Field.Value:=Now();
end;
主要的控件是EhLib系列。DBEditEh,DBGridEh...
主要不是这个问题,因为我其它的窗口也一样。而其它的窗口并没有上面的代码。
出现这种情况基本上就是因为没有设关键字的原因,不要急着从代码上找原因。
楼主,你检查了关键字和那些自增型id的设置没有?
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Products]
GO/****** Object: Table [dbo].[Products] Script Date: 2003-12-26 12:44:01 ******/
CREATE TABLE [dbo].[Products] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[proNo] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[proCode] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[proNameCn] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[proNameEn] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[proManufacturerNo] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[proManufacturerProductNo] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[proKindNo] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[proPackageCn] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[proPackageEn] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[proPrice] [money] NULL ,
[proLong] [float] NULL ,
[proWidth] [float] NULL ,
[proHeight] [float] NULL ,
[proPackingLong] [float] NULL ,
[proPackingWidth] [float] NULL ,
[proPackingHeight] [float] NULL ,
[proPackingVol] [float] NULL ,
[proPackingInnerBoxCount] [int] NULL ,
[proPackingOuterBoxQuantity] [int] NULL ,
[proGrossWeight] [float] NULL ,
[proNetWeight] [float] NULL ,
[proDescription] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[proRe] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
[AddDate] [smalldatetime] NULL ,
[ModifyDate] [smalldatetime] NULL ,
[Operator] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[OperatorEx] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Products] Script Date: 2003-12-26 12:58:33 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Products]
GO/****** Object: Table [dbo].[Products] Script Date: 2003-12-26 12:58:35 ******/
CREATE TABLE [dbo].[Products] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[proNo] [varchar] (50) NOT NULL ,
[proCode] [varchar] (50) NULL ,
[proNameCn] [varchar] (100) NULL ,
[proNameEn] [varchar] (100) NULL ,
[proManufacturerNo] [varchar] (20) NULL ,
[proManufacturerProductNo] [varchar] (50) NULL ,
[proKindNo] [varchar] (20) NULL ,
[proPackageCn] [varchar] (100) NULL ,
[proPackageEn] [varchar] (100) NULL ,
[proPrice] [money] NULL ,
[proLong] [float] NULL ,
[proWidth] [float] NULL ,
[proHeight] [float] NULL ,
[proPackingLong] [float] NULL ,
[proPackingWidth] [float] NULL ,
[proPackingHeight] [float] NULL ,
[proPackingVol] [float] NULL ,
[proPackingInnerBoxCount] [int] NULL ,
[proPackingOuterBoxQuantity] [int] NULL ,
[proGrossWeight] [float] NULL ,
[proNetWeight] [float] NULL ,
[proDescription] [varchar] (255) NULL ,
[proRe] [ntext] NULL ,
[AddDate] [smalldatetime] NULL ,
[ModifyDate] [smalldatetime] NULL ,
[Operator] [varchar] (50) NULL ,
[OperatorEx] [varchar] (50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GOALTER TABLE [dbo].[Products] WITH NOCHECK ADD
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED
(
[proNo]
) ON [PRIMARY]
GO CREATE INDEX [IX_Products] ON [dbo].[Products]([ID]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_1] ON [dbo].[Products]([proNo]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_2] ON [dbo].[Products]([proCode]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_3] ON [dbo].[Products]([proNameCn]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_4] ON [dbo].[Products]([proNameEn]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_5] ON [dbo].[Products]([proManufacturerNo]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_6] ON [dbo].[Products]([proManufacturerProductNo]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_7] ON [dbo].[Products]([proKindNo]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_8] ON [dbo].[Products]([proPackageCn]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_9] ON [dbo].[Products]([proPackageEn]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_10] ON [dbo].[Products]([proPrice]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_11] ON [dbo].[Products]([proLong]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_12] ON [dbo].[Products]([proWidth]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_13] ON [dbo].[Products]([proHeight]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_14] ON [dbo].[Products]([proPackingLong]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_15] ON [dbo].[Products]([proPackingVol]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_16] ON [dbo].[Products]([proPackingInnerBoxCount]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_17] ON [dbo].[Products]([proPackingOuterBoxQuantity]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_18] ON [dbo].[Products]([proGrossWeight]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_19] ON [dbo].[Products]([proNetWeight]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_20] ON [dbo].[Products]([proDescription]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_21] ON [dbo].[Products]([AddDate]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_22] ON [dbo].[Products]([ModifyDate]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_23] ON [dbo].[Products]([Operator]) ON [PRIMARY]
GO CREATE INDEX [IX_Products_24] ON [dbo].[Products]([OperatorEx]) ON [PRIMARY]
GO
[AddDate] [smalldatetime] NULL ,
[ModifyDate] [smalldatetime] NULL ,我原来是用DateTime(Access中的日期).现在用smalldatetime。可能是现在的字段已经不能够保存原来的字段了吧?原因可能如下: (2003-12-26 13:43:21) 帆船
那是数值类型在数据库中转换不成功的原因。(2003-12-26 13:48:50) 帆船
没有搞错,我以前出现过,
那是因为第一次保存时,虽然把记录保存了,
但里面某个字段转换出错。
其实在读出来时已经出错了,但在保存时,才会提示出来大家继续讨论。
是不是使用了.refresh方法?建议:重新Open一下.该记录已经被删除,数据库中已经不存在了.