| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 917 人关注过本帖
标题:[求助]有关数据库SQL修改语句的问题
取消只看楼主 加入收藏
xiexinxing
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-4-19
收藏
 问题点数:0 回复次数:0 
[求助]有关数据库SQL修改语句的问题

下面是个人员管理系统的部分代码

unit Unit3;

interface

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

type
TForm3 = class(TForm)
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Panel1: TPanel;
ID_Edit: TEdit;
name_Edit: TEdit;
sex_ComboBox: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
age_Edit: TEdit;
bplace_Edit: TEdit;
marr_ComboBox: TComboBox;
edu_ComboBox: TComboBox;
job_Edit: TEdit;
password_Edit1: TEdit;
password_Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Panel2: TPanel;
BitBtn4: TBitBtn;
ADOQuery1ID: TWideStringField;
ADOQuery1name: TWideStringField;
ADOQuery1sex: TWideStringField;
ADOQuery1age: TIntegerField;
ADOQuery1Birthplace: TWideStringField;
ADOQuery1MaritalStatus: TWideStringField;
ADOQuery1Education: TWideStringField;
ADOQuery1Occupational: TWideStringField;
ADOQuery1password: TWideStringField;
Edit1: TEdit;
Edit2: TEdit;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
BitBtn5: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure ADOQuery1AfterScroll(DataSet: TDataSet);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);

private
procedure redisplay;
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation
uses
unit2;

{$R *.dfm}
procedure TForm3.BitBtn1Click(Sender: TObject);
var
i:integer;
j:string;
qrylist:Tadoquery;
begin
qrylist:=Tadoquery.Create(self);
qrylist.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\人员管理.mdb;Persist Security Info=False';
with qrylist do
begin
close;
sql.Clear;
sql.Text:='select max(ID) as ID from peopleinformation ';
open;
end;
i:=strtoint(qrylist.fieldbyname('ID').AsString)+10001;
j:=copy(inttostr(i),2,4);
ID_edit.Text:=j;
name_edit.Enabled :=true ;
sex_combobox.Enabled :=true ;
age_edit.Enabled :=true ;
bplace_edit.Enabled :=true ;
marr_combobox.Enabled :=true ;
edu_combobox.Enabled :=true ;
job_edit.Enabled :=true ;
password_edit1.Enabled :=true ;
password_edit2.Enabled :=true ;
name_edit.Text:='';
sex_combobox.text :='';
age_edit.text :='';
bplace_edit.text :='';
marr_combobox.text :='';
edu_combobox.text :='';
job_edit.text :='';
password_edit1.text := '';
password_edit2.Text:='';

end;

procedure TForm3.BitBtn2Click(Sender: TObject);
var
strtemp:string;
begin
if trim(self.sex_ComboBox.Text)='' then
self.sex_ComboBox.Text:='男';
if trim(self.age_Edit.Text)='' then
self.age_Edit.Text:='0';
if trim(self.marr_ComboBox.Text)='' then
self.marr_ComboBox.Text:='未婚';
if trim(self.job_Edit.Text)='' then
self.job_Edit.Text:='其他' ;
if trim(self.password_Edit1.Text)='' then
self.password_Edit1.Text:='1234';
if trim(self.password_Edit1.Text)<>trim(self.password_Edit2.Text) then
begin
showmessage('密码输入错误,请重新输入');
self.password_Edit1.Text:='';
self.password_Edit2.Text:='';
password_edit1.SetFocus;
end
else
if trim(self.name_Edit.text)='' then
begin
showmessage('请输入姓名');
name_edit.SetFocus;
end
else
if trim(self.bplace_Edit.Text)='' then
begin
showmessage('请输入籍贯');
self.bplace_Edit.SetFocus;
end
else
if trim(self.edu_ComboBox.Text)='' then
begin
showmessage('请输入文化程度');
self.edu_ComboBox.SetFocus;
end
else
begin
with adoquery1 do
begin
close;
sql.Clear;
strtemp:= 'insert into peopleinformation values ('
+quotedstr(ID_edit.Text)+','+quotedstr(name_edit.Text)+','+quotedstr(self.sex_ComboBox.Text)+','+self.age_Edit.Text+','
+quotedstr(self.bplace_Edit.Text)+','+quotedstr(self.marr_ComboBox.Text)+','+quotedstr(self.edu_ComboBox.Text)+','
+quotedstr(self.job_Edit.Text)+','+quotedstr(self.password_Edit1.Text)+')' ;
sql.Add(strtemp);
execsql;
end;
end;
self.redisplay;
end;

procedure TForm3.BitBtn3Click(Sender: TObject);
begin
form3.Close;
end;

procedure TForm3.ADOQuery1AfterScroll(DataSet: TDataSet);
begin
self.ID_Edit.Text:=self.ADOQuery1.fieldbyname('ID').AsString;
self.sex_ComboBox.Text:=self.ADOQuery1.fieldbyname('sex').AsString;
self.age_Edit.Text:=self.ADOQuery1.fieldbyname('age').AsString;
self.name_Edit.Text:=self.ADOQuery1.fieldbyname('name').AsString;
self.bplace_Edit.Text:=self.ADOQuery1.fieldbyname('birthplace').AsString;
self.marr_Combobox.Text:=self.ADOQuery1.fieldbyname('maritalstatus').AsString;
self.edu_ComboBox.Text:=self.ADOQuery1.fieldbyname('education').AsString;
self.job_Edit.Text:=self.ADOQuery1.fieldbyname('Occupational').AsString;
self.password_Edit1.Text:=self.ADOQuery1.fieldbyname('password').AsString;
self.password_Edit2.Text:=self.password_Edit1.Text;
end;

procedure TForm3.redisplay;
var
qry:Tadoquery;
begin
qry:=Tadoquery.Create(self);
qry.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\人员管理.mdb;Persist Security Info=False';
with qry do
begin
close;
sql.Clear;
sql.Text:='select * from peopleinformation';
open;
end;
end;

procedure TForm3.BitBtn6Click(Sender: TObject);
var
delqry:Tadoquery;
begin
if application.MessageBox('是否继续','提示信息',mb_yesno)=id_yes then
begin
delqry:=Tadoquery.Create(self);
delqry.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\人员管理.mdb;Persist Security Info=False';
with delqry do
begin
close;
sql.Clear;
sql.Text:='select * from peopleinformation where ID='+quotedstr(ID_edit.Text);
execsql;
end;
self.redisplay;
end;
end;

procedure TForm3.BitBtn5Click(Sender: TObject);
begin
name_edit.Enabled :=true ;
sex_combobox.Enabled :=true ;
age_edit.Enabled :=true ;
bplace_edit.Enabled :=true ;
marr_combobox.Enabled :=true ;
edu_combobox.Enabled :=true ;
job_edit.Enabled :=true ;
password_edit1.Enabled :=true ;
password_edit2.Enabled :=true ;
end;

procedure TForm3.BitBtn7Click(Sender: TObject);
var
updqry:Tadoquery;
updstr:string;
begin
updqry:=Tadoquery.Create(self);
updqry.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\人员管理.mdb;Persist Security Info=False';
if trim(self.sex_ComboBox.Text)='' then
self.sex_ComboBox.Text:='男';
if trim(self.age_Edit.Text)='' then
self.age_Edit.Text:='0';
if trim(self.marr_ComboBox.Text)='' then
self.marr_ComboBox.Text:='未婚';
if trim(self.job_Edit.Text)='' then
self.job_Edit.Text:='其他' ;
if trim(self.password_Edit1.Text)='' then
self.password_Edit1.Text:='1234';
if trim(self.password_Edit1.Text)<>trim(self.password_Edit2.Text) then
begin
showmessage('输入密码不符,请重新输入');
password_edit1.SetFocus;
end
else
begin
with updqry do
begin
close;
sql.Clear;
updstr:='update peopleinformation set name='+quotedstr(name_edit.Text)+','
+'sex='+quotedstr(self.sex_ComboBox.Text)+','+'age='+age_Edit.Text+','
+'birthplace='+quotedstr(self.bplace_Edit.Text)+','+'maritalstatus='
+quotedstr(self.marr_ComboBox.Text)+','+'education='+quotedstr(self.edu_ComboBox.Text)
+','+'Occupational='+quotedstr(self.job_Edit.Text)+','+'password='+quotedstr(trim (self.password_Edit1.Text))
+' where ID='+quotedstr(ID_edit.Text);
sql.Text:=updstr;
execsql;
end;
end;
self.redisplay;
end;

end.



上面的问题我把加红的一段代码+','+'password='+quotedstr(trim (self.password_Edit1.Text))
删除就运行正常,不删除就会报说UPDATE语法错误.数据库中有password字段是文本类型的.没有长度输入要求.
另我把运行到sql.text:=updstr;时候的updstr值复制出到ACCESS数据库中输入修改语句可以正常执行,但是到DELPHI中就报错(UPDATE语法错误).把+','+'password='+quotedstr(trim (self.password_Edit1.Text))
删除就一切正常.请问什么问题啊?急啊!!哪个大哥能帮帮我吗?

搜索更多相关主题的帖子: SQL 数据库 语句 TEdit name 
2007-07-17 16:50
快速回复:[求助]有关数据库SQL修改语句的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026467 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved