用sql + Ado设置access的字段的默认值
程序员文章站
2022-05-09 09:04:41
...
procedure TFormLOrder.ModifyDB; var F: Integer; begin with TADOQuery.Create( nil ) do try // ConnectionString := GetAdoAccConStr(SoftPath + SendDataDir +LogisOrderDB); Connection := ADOCon; SQL.Add( ' Select * from ' + tblogistics_orders);
procedure TFormLOrder.ModifyDB; var F: Integer; begin with TADOQuery.Create(nil) do try // ConnectionString := GetAdoAccConStr(SoftPath + SendDataDir +LogisOrderDB); Connection := ADOCon; SQL.Add('Select * from ' + tblogistics_orders); //不能用 Select seller_flag from ,否则会报 参数 seller_flag 没有默认值 Open; if FieldList.Find('seller_flag') = nil then //不能用 FieldByName,因为参数必须是存在的字段,否则会产生异常 begin Close; SQL.Clear; SQL.Add('ALTER TABLE ' + tblogistics_orders); SQL.Add('ADD COLUMN seller_flag INTEGER DEFAULT 0'); // ADOCon.Execute(sql.Text, F); //这个也可以的,并 不是 必须用这个 ExecSQL; end; // Close; sql.Clear; sql.Add('Select sub_tids from ' + tblogistics_orders); Open; if (FieldCount > 0) and (FieldByName('sub_tids').Size 255