我插入数据怎么没有反映?但是Showmessage('该用户名已存在,请重新输入!');可以实现。谢谢!!!!procedure TFormyhzc.Button1Click(Sender: TObject);
begin
with DataModulenjsh do
begin
ADOQueryyhzc.Close;
ADOQueryyhzc.SQL.Clear;
ADOQueryyhzc.SQL.Text := 'select username from tableyhmm where username = '''+ Edit1.Text + '''';
ADOQueryyhzc.open;
if ADOQueryyhzc.RecordCount <> 0 then
begin
Showmessage('该用户名已存在,请重新输入!');
Edit1.Clear;
Edit2.Clear;
Edit1.SetFocus;
end else if ADOQueryyhzc.RecordCount = 0 then
begin
if not ADOQueryyhzc.Eof then
begin
try
ADOQueryyhzc.Close;
ADOQueryyhzc.SQL.Clear;
ADOQueryyhzc.SQL.Add('INSERT INTO TABLEyhmm(username,userpassword)');
ADOQueryyhzc.SQL.Add(' VALUES(:username,:userpassword)');
ADOQueryyhzc.Parameters.ParamByName('username').Value:= Edit1.Text;
ADOQueryyhzc.Parameters.ParamByName('userpassword').Value:= Edit2.Text;
ADOQueryyhzc.Open; Showmessage('注册成功!');
Formyhdl.Show;
except
showmessage('注册失败!');
end;
Formyhzc.Close;
end
else
ADOQueryyhzc.Next;
end;
end;
end;
begin
with DataModulenjsh do
begin
ADOQueryyhzc.Close;
ADOQueryyhzc.SQL.Clear;
ADOQueryyhzc.SQL.Text := 'select username from tableyhmm where username = '''+ Edit1.Text + '''';
ADOQueryyhzc.open;
if ADOQueryyhzc.RecordCount <> 0 then
begin
Showmessage('该用户名已存在,请重新输入!');
Edit1.Clear;
Edit2.Clear;
Edit1.SetFocus;
end else if ADOQueryyhzc.RecordCount = 0 then
begin
if not ADOQueryyhzc.Eof then
begin
try
ADOQueryyhzc.Close;
ADOQueryyhzc.SQL.Clear;
ADOQueryyhzc.SQL.Add('INSERT INTO TABLEyhmm(username,userpassword)');
ADOQueryyhzc.SQL.Add(' VALUES(:username,:userpassword)');
ADOQueryyhzc.Parameters.ParamByName('username').Value:= Edit1.Text;
ADOQueryyhzc.Parameters.ParamByName('userpassword').Value:= Edit2.Text;
ADOQueryyhzc.Open; Showmessage('注册成功!');
Formyhdl.Show;
except
showmessage('注册失败!');
end;
Formyhzc.Close;
end
else
ADOQueryyhzc.Next;
end;
end;
end;
try
ADOQueryyhzc.Close;
ADOQueryyhzc.SQL.Clear;
ADOQueryyhzc.SQL.Add('INSERT INTO TABLEyhmm(username,userpassword)');
ADOQueryyhzc.SQL.Add(' VALUES(:username,:userpassword)');
ADOQueryyhzc.Parameters.ParamByName('username').Value:= Edit1.Text;
ADOQueryyhzc.Parameters.ParamByName('userpassword').Value:= Edit2.Text;
ADOQueryyhzc.Open;------------>ADOQueryyhzc.ExecSql........
但是不管输入什么,显示的都是:‘该用户名已存在,请重新输入!’