请问如何更新数据库? |
缺席
|
hyan116
一般會員 發表:1 回覆:2 積分:0 註冊:2004-04-22 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
|
hyan116
一般會員 發表:1 回覆:2 積分:0 註冊:2004-04-22 發送簡訊給我 |
我编写的程式全文如下,请高手指教一下,一旦执行到query3.SQL.Add('update carddata set xh=xh1 ');那一部分就报错“table is read only"
因为接触delphi时间不久,了解不是很全面,所以一直没有找到原因。 unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, Db, DBTables, DBCtrls, jpeg; type
TForm1 = class(TForm)
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Timer1: TTimer;
Label3: TLabel;
Query1: TQuery;
DataSource1: TDataSource;
Database1: TDatabase;
Label4: TLabel;
Table1: TTable;
Query2: TQuery;
DBText1: TDBText;
Image1: TImage;
Query3: TQuery;
Label1: TLabel;
Label5: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1;
rowcount,rdm,flag,count,xh,xh1:integer;
cardnum,nm: string; implementation {$R *.DFM} procedure TForm1.BitBtn1Click(Sender: TObject);
begin
timer1.Enabled:=True;
label1.caption:='第'+inttostr(count)+'位';
label5.Caption:='';
end; procedure TForm1.BitBtn2Click(Sender: TObject);
var
vsSql:string;
begin
timer1.Enabled:=false;
table1.Close;
{messagedlg(cardnum,mtWarning,[mbOK],0);
rowcount:=rowcount-1; } query1.close;
query1.ParamByName('p_seq_no').AsInteger:=rdm;
query1.Prepare;
query1.open;
//cardnum:=query1.Fields[0].AsString ;
cardnum:=query1.fieldbyname('cardno').asstring;
nm:=query1.fieldbyname('name').asstring; count:=count+1;
label5.caption:=nm;
xh:=rdm; query2.SQL.Clear;
query2.SQL.Add('update carddata set stat=1');
query2.SQL.Add(' where cardno=:p_cardno');
query2.ParamByName('p_cardno').AsString:=cardnum;
query2.Prepare;
{showmessage(query2.ParamByName('p_cardno').AsString);}
query2.ExecSQL; query2.SQL.Clear;
query2.SQL.Add('insert into card select * from carddata');
query2.SQL.Add(' where stat=1');
query2.Prepare;
query2.ExecSQL; query2.SQL.Clear;
query2.SQL.Add('delete from carddata where stat=1');
query2.Prepare;
query2.ExecSQL; while xh
|
hyan116
一般會員 發表:1 回覆:2 積分:0 註冊:2004-04-22 發送簡訊給我 |
另附上其他定义 object Form1: TForm1
Left = 338
Top = 400
Width = 808
Height = 580
VertScrollBar.Position = 22
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 0
Top = -22
Width = 1025
Height = 713
Stretch = True
Transparent = True
end
object Label2: TLabel
Left = 48
Top = 418
Width = 265
Height = 65
Alignment = taCenter
AutoSize = False
Caption = #24184#36816#21592#24037#65306
Font.Charset = GB2312_CHARSET
Font.Color = clYellow
Font.Height = -48
Font.Name = #21326#25991#34892#26999
Font.Style = []
ParentFont = False
Transparent = True
Layout = tlCenter
end
object Label3: TLabel
Left = 312
Top = 66
Width = 23
Height = 98
Font.Charset = GB2312_CHARSET
Font.Color = clYellow
Font.Height = -96
Font.Name = #21326#25991#26032#39759
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = False
Transparent = True
end
object DBText1: TDBText
Left = 248
Top = 330
Width = 729
Height = 121
Alignment = taCenter
Color = clInactiveCaptionText
DataField = 'cardno'
DataSource = DataSource1
Font.Charset = GB2312_CHARSET
Font.Color = clRed
Font.Height = -75
Font.Name = #26999#20307'_GB2312'
Font.Style = []
ParentColor = False
ParentFont = False
ParentShowHint = False
Transparent = True
ShowHint = True
end
object Label4: TLabel
Left = 24
Top = 194
Width = 686
Height = 59
Caption = ' '#19968#31561#22870#24184#36816#25277#22870
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clYellow
Font.Height = -56
Font.Name = #21326#25991#34892#26999
Font.Style = []
ParentColor = False
ParentFont = False
ParentShowHint = False
ShowHint = False
Transparent = True
end
object Label1: TLabel
Left = 96
Top = 368
Width = 12
Height = 51
Font.Charset = GB2312_CHARSET
Font.Color = clYellow
Font.Height = -48
Font.Name = #21326#25991#34892#26999
Font.Style = []
ParentFont = False
Transparent = True
end
object Label5: TLabel
Left = 464
Top = 440
Width = 33
Height = 64
Font.Charset = GB2312_CHARSET
Font.Color = clRed
Font.Height = -64
Font.Name = #26999#20307'_GB2312'
Font.Style = [fsBold]
ParentFont = False
Transparent = True
end
object BitBtn1: TBitBtn
Left = 232
Top = 592
Width = 97
Height = 43
Caption = #24320#22987
Font.Charset = GB2312_CHARSET
Font.Color = clBlack
Font.Height = -24
Font.Name = #26999#20307'_GB2312'
Font.Style = []
ParentFont = False
TabOrder = 0
OnClick = BitBtn1Click
Kind = bkOK
end
object BitBtn2: TBitBtn
Left = 464
Top = 592
Width = 97
Height = 43
Caption = #20572#27490
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -21
Font.Name = #23435#20307
Font.Style = []
ParentFont = False
TabOrder = 1
OnClick = BitBtn2Click
Kind = bkCancel
end
object BitBtn3: TBitBtn
Left = 712
Top = 592
Width = 97
Height = 43
Caption = #36864#20986
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -24
Font.Name = #23435#20307
Font.Style = []
ParentFont = False
TabOrder = 2
OnClick = BitBtn3Click
Kind = bkClose
end
object Timer1: TTimer
Enabled = False
Interval = 100
OnTimer = Timer1Timer
Left = 56
Top = 629
end
object Query1: TQuery
DatabaseName = 'luck'
SQL.Strings = (
'select * from carddata where seq_no=:p_seq_no'
'and stat=0')
Left = 56
Top = 520
ParamData = <
item
DataType = ftInteger
Name = 'p_seq_no'
ParamType = ptInput
end>
end
object DataSource1: TDataSource
DataSet = Query1
Left = 48
Top = 344
end
object Database1: TDatabase
AliasName = 'bankdata'
Connected = True
DatabaseName = 'luck'
LoginPrompt = False
Params.Strings = (
'USER NAME=sa'
'PASSWORD=')
SessionName = 'Default'
Left = 48
Top = 384
end
object Table1: TTable
Active = True
DatabaseName = 'bankdata'
MasterSource = DataSource1
TableName = 'carddata'
Left = 120
Top = 352
end
object Query2: TQuery
DatabaseName = 'luck'
SQL.Strings = (
'select * from carddata where 1>2')
Left = 56
Top = 568
end
object Query3: TQuery
DatabaseName = 'luck'
RequestLive = True
SQL.Strings = (
'select * from carddata where xh>0')
Left = 80
Top = 96
end
end
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |