太奇怪了!(5分)

  • 主题发起人 主题发起人 beyzhzj
  • 开始时间 开始时间
B

beyzhzj

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是i:=adodataset.recordcount,为什么得到的记录个数始终为1呢?每次增删ACCESS
中的记录,上面的i始终为1, 这个我也设了(adodataset.cursorlocation:=clUseClient)
 
adodataset.recordcount是SELECT后的并不是你添加或删除记录的个数.
 
adodataset.Last,再访问就ok了
 
以上我试了,不行。
 
TO beyzhzj:
spymaster,说得没错呀
你的I赋值在更新以前吧--即增删ACCESS以前
能否贴出CODE
 
max_dataset:=Tadodataset.Create(self);
with max_dataset do
begin
connection:=form3.ADOConnection1;
commandtype:=cmdtext;
commandtext:='select max(BB02) as zuida from BOMB where bb01='+''''+trim(edit1.Text)+'''';
open;
end;
showmessage(inttostr(max_dataset.RecordCount));
 
把你的单元文件贴出来看看~
 
select max(BB02) as zuida from
看一下你的SQL 取最大值的BBO2 作为zuida 可能有两条或两条以上的最大记录?
注意最大
 
你SELECT的意思是求最大值,返回肯定就是一条记录了~
 
unit bom_edit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Buttons, ExtCtrls, Grids, DBGrids,ADODB, DB;

type
Tbomedit = class(TForm)
Panel1: TPanel;
Shape1: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Edit2: TEdit;
edit1: TEdit;
Label4: TLabel;
Edit4: TEdit;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Memo1: TMemo;
Label7: TLabel;
Label5: TLabel;
Label6: TLabel;
GroupBox1: TGroupBox;
Label8: TLabel;
edit5: TEdit;
Label9: TLabel;
Edit6: TEdit;
Label10: TLabel;
Edit7: TEdit;
Label11: TLabel;
Edit8: TEdit;
Label12: TLabel;
Edit9: TEdit;
Label13: TLabel;
Edit10: TEdit;
Label14: TLabel;
Edit11: TEdit;
Label15: TLabel;
jl: TDateTimePicker;
sxr: TDateTimePicker;
Label16: TLabel;
GroupBox2: TGroupBox;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
Label17: TLabel;
Edit12: TEdit;
ADOCommand1: TADOCommand;
StringGrid1: TStringGrid;
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edit1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1CellClick(Column: TColumn);
procedure Edit6KeyPress(Sender: TObject; var Key: Char);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure Edit9KeyPress(Sender: TObject; var Key: Char);
procedure jlKeyPress(Sender: TObject; var Key: Char);
procedure sxrKeyPress(Sender: TObject; var Key: Char);
procedure Edit11KeyPress(Sender: TObject; var Key: Char);
procedure Edit10KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
function data_edit(sql_edit:string):boolean;
function chongfu_xh(int1:integer):integer;
function chongfu_lh(str1:string):integer;
function lh_exit(str1:string):integer;
end;
 
对,不信你可以试一试。哪怕有两条记录值相同
 
>>select max(BB02) as zuida from BOMB
你用了 max() 函数当然 max_dataset.RecordCount=1 了.
max()是取最大值,max_dataset所返回的记录肯定是1.
你想得到什么结果?数据库中的纪录数吗
......
select count(*) as icount from BOMB
.....
showmessage(max_dataset.FiledByName('icount').Asstring);
 
是的空值也返回一条 ,你可以
select Isnull(max(BB02),'不存在记录') as zuida from BOMB
在程序中判断一下
不光看记录数,而且返回值
 
告诉一下你想干什么吧?
 
后退
顶部