点击按钮没有反映,我想是adoquery查询记录的问题,但是我知道怎么改.各位帮帮忙!
procedure Tzhuce_form.ok_bitbtnClick(Sender: TObject);
var
name:string;
testStream:TMemoryStream;
begin
if ((class_edit.text='')or(num_edit.text='')or(username_edit.Text='')or(pw_edit.Text='')
or(combobox.Text='')) then
begin
application.messagebox('输入正确的信息!','提示',mb_ok);
class_edit.setfocus;
exit;
end;
adoquery1.Close;
adoquery1.sql.clear;
adoquery1.SQL.add('select * from student');
adoquery1.Open;
while not adoquery1.Eof do
begin
name:=trim(adoquery1.FieldValues['姓名']);
adoquery1.First; ///我想应该是这地方的问题
adoquery1.Next;
if(username_edit.text=name) then
begin
application.messagebox('用户名已存在!','提示',mb_ok);
username_edit.clear;
pw_edit.Clear;
//combobox1.clear;
//image1.Picture:=nil;
username_edit.setfocus;
exit;
end;
end;
testStream:=TMemoryStream.Create; //创建内存流
Image1.Picture.Graphic.SaveToStream(testStream);//将图片存入内存流
with ADOQuery1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='insert into student(班级名称,学号,姓名,密码,头像)' +
'VALUES(:班级名称,:学号,:姓名,:密码,:头像)';
parameters.paramByName('班级名称').Value:=class_edit.text;
parameters.paramByName('学号').Value:=num_edit.Text;
parameters.paramByName('姓名').Value:=username_edit.Text;
parameters.paramByName('密码').Value:=pw_edit.Text;
parameters.ParamByName('头像').LoadFromStream(testStream,ftBlob);
adoquery1.ExecSQL;
end;
showmessage('用户添加成功,请重新启动程序登陆!');
login_form.show;
self.Close;
end;
procedure Tzhuce_form.ok_bitbtnClick(Sender: TObject);
var
name:string;
testStream:TMemoryStream;
begin
if ((class_edit.text='')or(num_edit.text='')or(username_edit.Text='')or(pw_edit.Text='')
or(combobox.Text='')) then
begin
application.messagebox('输入正确的信息!','提示',mb_ok);
class_edit.setfocus;
exit;
end;
adoquery1.Close;
adoquery1.sql.clear;
adoquery1.SQL.add('select * from student');
adoquery1.Open;
while not adoquery1.Eof do
begin
name:=trim(adoquery1.FieldValues['姓名']);
adoquery1.First; ///我想应该是这地方的问题
adoquery1.Next;
if(username_edit.text=name) then
begin
application.messagebox('用户名已存在!','提示',mb_ok);
username_edit.clear;
pw_edit.Clear;
//combobox1.clear;
//image1.Picture:=nil;
username_edit.setfocus;
exit;
end;
end;
testStream:=TMemoryStream.Create; //创建内存流
Image1.Picture.Graphic.SaveToStream(testStream);//将图片存入内存流
with ADOQuery1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='insert into student(班级名称,学号,姓名,密码,头像)' +
'VALUES(:班级名称,:学号,:姓名,:密码,:头像)';
parameters.paramByName('班级名称').Value:=class_edit.text;
parameters.paramByName('学号').Value:=num_edit.Text;
parameters.paramByName('姓名').Value:=username_edit.Text;
parameters.paramByName('密码').Value:=pw_edit.Text;
parameters.ParamByName('头像').LoadFromStream(testStream,ftBlob);
adoquery1.ExecSQL;
end;
showmessage('用户添加成功,请重新启动程序登陆!');
login_form.show;
self.Close;
end;
......
adoquery1.Close;
adoquery1.sql.clear;
adoquery1.SQL.add('select * from student where 姓名=''' + username_edit.text + '''');
adoquery1.Open;
if not adoquery1.IsEmpty then
begin
application.messagebox('用户名已存在!','提示',mb_ok);
username_edit.clear;
pw_edit.Clear;
//combobox1.clear;
//image1.Picture:=nil;
username_edit.setfocus;
exit;
end;
......
adoquery1.Next; 在你的循环里,始终都是第一条,你可以在你的原来代码中把adoquery1.First删除或移到
while not adoquery1.Eof do //这句的前面
var
name:string;
testStream:TMemoryStream;
begin
if ((class_edit.text='')or(num_edit.text='')or(username_edit.Text='')or(pw_edit.Text='')
or(combobox.Text='')) then
begin
application.messagebox('输入正确的信息!','提示',mb_ok);
class_edit.setfocus;
exit;
end;
adoquery1.Close;
adoquery1.sql.clear;
adoquery1.SQL.add('select * from student');
adoquery1.Open;
if not adoquery1.IsEmpty do //修改
begin
name:=trim(adoquery1.FieldValues['姓名']);
if(username_edit.text=name) then
begin
application.messagebox('用户名已存在!','提示',mb_ok);
username_edit.clear;
pw_edit.Clear;
//combobox1.clear;
//image1.Picture:=nil;
username_edit.setfocus;
exit;
end;
end
else
begin
//修改
Application.messageBox('用户不存在!','提示',MB_OK+MB_ICONINFORMATION);
Exit;
end;
testStream:=TMemoryStream.Create; //创建内存流
Image1.Picture.Graphic.SaveToStream(testStream);//将图片存入内存流
with ADOQuery1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='insert into student(班级名称,学号,姓名,密码,头像)' +
'VALUES(:班级名称,:学号,:姓名,:密码,:头像)';
parameters.paramByName('班级名称').Value:=class_edit.text;
parameters.paramByName('学号').Value:=num_edit.Text;
parameters.paramByName('姓名').Value:=username_edit.Text;
parameters.paramByName('密码').Value:=pw_edit.Text;
parameters.ParamByName('头像').LoadFromStream(testStream,ftBlob);
adoquery1.ExecSQL;
adoquery1.Close//修改
end;
showmessage('用户添加成功,请重新启动程序登陆!');
login_form.show;
self.Close;
end;
你这样是让记录指针总是跑到第一条,再下移一下,重复循环.