用ADOQuery连接Access数据库是,想生成数据库是最大编号
语句如下:
sql.add('select max(isnull(seria,0))+1 max_serial from customer');//数据库字段serial为数字
运行时提示为:Project raised exception class EoleException with message'语法错误(操作符丢失)在查询表达式'max(isnull(serial,0))+1 max_serial'中'。
请问错误在哪!
在线等待!!!!!!!!
语句如下:
sql.add('select max(isnull(seria,0))+1 max_serial from customer');//数据库字段serial为数字
运行时提示为:Project raised exception class EoleException with message'语法错误(操作符丢失)在查询表达式'max(isnull(serial,0))+1 max_serial'中'。
请问错误在哪!
在线等待!!!!!!!!
如果改成sql.add('select max(isnull(seria,0))+1 as max_serial from customer');时
运行是提示:Project raised exception class EoleException with message'用于函数参数的个数不对在查询表达式'max(isnull(serial,0))+1'中'。
这是怎么回事?
所以用判断是否为空的函数和取得字段最大编号函数:isnull(max(serial),0)+1 as max_serial ,
运行时系统提示:用于函数参数的个数不对,难道是max_serial的原因吗。我的完整代码如下:
procedure TF_main.FormShow(Sender: TObject);
begin
pagecontrol1.ActivePageIndex:=0;
with adoquery1 do
begin
if active then
close;
sql.Clear;
sql.Add('select isnull(max(serial),0)+1 as max_serial from customer');
showmessage(sql.Text);
open;
yjr_serial:=fieldbyname('max_serial').AsString;
new_serial:=strtoint(yjr_serial)+1;
yjr_serial:=inttostr(new_serial);
edit1.Text:=yjr_serial;
edit1.Enabled:=false;
edit2.SetFocus;
end;
end;
在access中,isnull只能用来判断控件的值是否为null。还是在adoquery中加个判断吧,记录数量为0时给它赋值个1;不为0时才用到max()函数。