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. 展开
 我来答
liucanwei509
2012-08-04 · 超过20用户采纳过TA的回答
知道答主
回答量:77
采纳率:0%
帮助的人:49.9万
展开全部
你代码贴出来都没有排版,谁愿意看啊,而且问题都没有。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ZESTRON
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸... 点击进入详情页
本回答由ZESTRON提供
LUJIAYU110
2012-08-07 · 超过22用户采纳过TA的回答
知道答主
回答量:107
采纳率:100%
帮助的人:43.8万
展开全部
怎一个乱字了得。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
焊板子的兔子
2012-08-04 · TA获得超过879个赞
知道小有建树答主
回答量:275
采纳率:50%
帮助的人:162万
展开全部
你的问题是什么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式