Delphi7编写数据库增删改查程序,运行到修改那里就会报错,我是新手望大侠指点,说的越详细越好,谢谢! 5
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOConnection1: TADOConnection;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Button5: TButton;
Edit5: TEdit;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button5Click(Sender: TObject);
procedure DataSource1DataChange(Sender: TObject; Field: TField);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit5.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject); //增加
begin
ADOQuery1.SQL.Add('insert into SysUntUser values('''+edit1.Text+''','''+edit2.Text+''','''+edit3.Text+''','''+edit4.Text+''')');
ADOQuery1.ExecSQL;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.ADD('select*from sysuntuser');
ADOQuery1.Open;
end;
procedure TForm1.Button2Click(Sender: TObject);//删除
begin
if ADOQuery1.recordCount=0 then
showMessage('记录为空不能为删除')
else
begin
if MessageDlg('确定要删除吗?',mtInformation,[mbOK,mbCancel],0)=mrOK then
ADOQuery1.delete;
end;
end;
procedure TForm1.Button3Click(Sender: TObject); //修改
begin
with ADOQuery2 do
begin
close;
sql.Clear;
sql.Add('update SysUntUser set 用户编码='''+trim(edit1.Text)+''',
用户名称='''+trim(edit2.Text)+''',用户密码='''+trim(edit3.Text)+''',单位名称
='''+trim(edit3.Text)'''');//整个sql.Add这句开始报错!
execsql;
end;
FormShow(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adoQuery1.Clear;
adoQuery1.SQL.Add('select*from SysUntUser');
adoQuery1.Open;
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
edit1.Text:=inttostr(ADOQuery1.fieldbyname('用户编码').AsInteger);
edit2.Text:=ADOQuery1.Fieldbyname('用户名称').AsString;
edit3.Text:=ADOQuery1.Fieldbyname('用户密码').AsString;
edit4.Text:=ADOQuery1.Fieldbyname('单位名称').AsString;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select*from sysuntuser where 用户编码='''+edit1.Text+'''');
adoquery1.Open;
end; 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOConnection1: TADOConnection;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Button5: TButton;
Edit5: TEdit;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button5Click(Sender: TObject);
procedure DataSource1DataChange(Sender: TObject; Field: TField);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit5.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject); //增加
begin
ADOQuery1.SQL.Add('insert into SysUntUser values('''+edit1.Text+''','''+edit2.Text+''','''+edit3.Text+''','''+edit4.Text+''')');
ADOQuery1.ExecSQL;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.ADD('select*from sysuntuser');
ADOQuery1.Open;
end;
procedure TForm1.Button2Click(Sender: TObject);//删除
begin
if ADOQuery1.recordCount=0 then
showMessage('记录为空不能为删除')
else
begin
if MessageDlg('确定要删除吗?',mtInformation,[mbOK,mbCancel],0)=mrOK then
ADOQuery1.delete;
end;
end;
procedure TForm1.Button3Click(Sender: TObject); //修改
begin
with ADOQuery2 do
begin
close;
sql.Clear;
sql.Add('update SysUntUser set 用户编码='''+trim(edit1.Text)+''',
用户名称='''+trim(edit2.Text)+''',用户密码='''+trim(edit3.Text)+''',单位名称
='''+trim(edit3.Text)'''');//整个sql.Add这句开始报错!
execsql;
end;
FormShow(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adoQuery1.Clear;
adoQuery1.SQL.Add('select*from SysUntUser');
adoQuery1.Open;
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
edit1.Text:=inttostr(ADOQuery1.fieldbyname('用户编码').AsInteger);
edit2.Text:=ADOQuery1.Fieldbyname('用户名称').AsString;
edit3.Text:=ADOQuery1.Fieldbyname('用户密码').AsString;
edit4.Text:=ADOQuery1.Fieldbyname('单位名称').AsString;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select*from sysuntuser where 用户编码='''+edit1.Text+'''');
adoquery1.Open;
end; 展开
3个回答
展开全部
sql.Add('update SysUntUser set 用户编码='''+trim(edit1.Text)+''',
用户名称='''+trim(edit2.Text)+''',用户密码='''+trim(edit3.Text)+''',单位名称
='''+trim(edit3.Text)'''');//整个sql.Add这句开始报错!
却少条件,不然无法知道你更新的是那里。
建议所有汉语改成英文。
用户名称='''+trim(edit2.Text)+''',用户密码='''+trim(edit3.Text)+''',单位名称
='''+trim(edit3.Text)'''');//整个sql.Add这句开始报错!
却少条件,不然无法知道你更新的是那里。
建议所有汉语改成英文。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果没解决了 晚上上线找我,529549601QQ
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
报什么错,检查一下SQL语句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询