Delphi的一个操作数据库问题
unitbddg1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit bddg1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, DB, DBTables, StdCtrls, Grids, DBGrids, ExtCtrls;type Tbddg1_Form = class(TForm) GroupBox1: TGroupBox; xm_LEdit: TLabeledEdit; DBGrid1: TDBGrid; Button1: TButton; Button2: TButton; PopupMenu1: TPopupMenu; Query1: TQuery; DataSource1: TDataSource; N1: TMenuItem; procedure Button1Click(Sender: TObject); procedure N1Click(Sender: TObject); procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;var bddg1_Form: Tbddg1_Form;implementation uses main;{$R *.dfm}procedure Tbddg1_Form.Button1Click(Sender: TObject);var xm,sqlstr:string;beginxm:=Trim(xm_LEdit.Text); if Length(xm)<1 then begin sqlstr:='select a.*,b.ZYMC as ZYMC,c.XBMC as XBMC from xsb a'; sqlstr:=sqlstr+'INNER JOIN zydm b ON a.ZYDM=b.ZYDM'; sqlstr:=sqlstr+'INNER JOIN xbdm c ON a.XBDM=c.XBDM'; end else begin xm:='%'+xm+'%'; sqlstr:='select a.*,b.ZYMC as ZYMC,c.XBMC as XBMC from xsb a'; sqlstr:=sqlstr+'INNER JOIN zydm b ON a.ZYDM=b.ZYDM'; sqlstr:=sqlstr+'INNER JOIN xbdm c ON a.XBDM=b.XBDM'; sqlstr:=sqlstr+'where (a.XM like '''+xm+''')'; end; Query1.Close; Query1.SQL.Clear; Query1.SQL.Add(sqlstr); Query1.Open; if Query1.RecordCount>0 then N1.Enabled:=true else N1.Enabled:=False;end;procedure Tbddg1_Form.N1Click(Sender: TObject);var xh,sqlstr:string;begin if Query1.FieldByName('ZT').AsInteger=0 then begin xh:=Query1.FieldByName('xh').AsString; sqlstr:='update xsb set ZT=1 where (XH='''+xh+''')'; with TQuery.Create(nil) do begin try SessionName:=Main_Form.Database1.SessionName; DataBaseName:=Main_Form.Database1.DatabaseName; sql.Clear; sql.Add(sqlstr); ExecSQL; finally Free; end; end; end else begin ShowMessage('该同学已经报道!'); exit; end;end;procedure Tbddg1_Form.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin if gdSelected in State then Exit; case Query1.FieldByName('ZT').AsInteger of 0:(Sender as TDBGrid).Canvas.Brush.Color:=clWindow; 1:(Sender as TDBGrid).Canvas.Brush.Color:=clYellow; 2:(Sender as TDBGrid).Canvas.Brush.Color:=clBlue; 3:(Sender as TDBGrid).Canvas.Brush.Color:=clRed; end; DbGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);end;procedure Tbddg1_Form.FormCreate(Sender: TObject);begin Query1.SessionName:=Main_Form.Database1.SessionName; Query1.DatabaseName:=Main_Form.Database1.DatabaseName;end;procedure Tbddg1_Form.FormClose(Sender: TObject; var Action: TCloseAction);beginMain_Form.N12.Enabled:=True;Action:=caFree;end;end.
展开
3个回答
展开全部
你代码贴出来都没有排版,谁愿意看啊,而且问题都没有。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
展开全部
怎一个乱字了得。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的问题是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询