ado,sql,dbgrid,edit(或用dbedit)修改表中数据的问题? 我想实现的功能是:1,当表单运行完后,鼠标点dbgrid上哪行,在edit中显示该行的所有数据,然后可以实行修改操作;2,若用dbedit并且不用dbnavigator,咋样实现修改操作,最好能有案例代码????? 请高手们帮帮忙!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; ADOTable1: TADOTable; Edit1: TEdit; Button1: TButton; Edit2: TEdit; Edit3: TEdit; procedure DataSource1DataChange(Sender: TObject; Field: TField); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);begin edit1.Text := (sender as TDataSource).DataSet.FieldByName('username').AsString; edit2.Text := (sender as TDataSource).DataSet.FieldByName('passwd').AsStringend;procedure TForm1.Button1Click(Sender: TObject);begin with adotable1 do begin if not Active then Active := true; edit; FieldByName('passwd').Value := Edit3.Text; Post; end;end;end.窗体文件如下:object Form1: TForm1 Left = 192 Top = 110 Width = 696 Height = 480 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 0 Top = 330 Width = 688 Height = 120 Align = alBottom DataSource = DataSource1 TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = [] end object Edit1: TEdit Left = 40 Top = 32 Width = 121 Height = 21 TabOrder = 1 Text = 'Edit1' end object Button1: TButton Left = 240 Top = 144 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 2 OnClick = Button1Click end object Edit2: TEdit Left = 40 Top = 64 Width = 121 Height = 21 TabOrder = 3 Text = 'Edit2' end object Edit3: TEdit Left = 40 Top = 96 Width = 121 Height = 21 TabOrder = 4 Text = 'Edit3' end object DataSource1: TDataSource AutoEdit = False DataSet = ADOTable1 OnDataChange = DataSource1DataChange Left = 216 Top = 48 end object ADOTable1: TADOTable Active = True ConnectionString = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' + 'fo=False;Initial Catalog=**;Data Source=.' CursorType = ctStatic TableName = 'userInfotb' Left = 296 Top = 56 endend 关键就是在grid的DataChange事件写上代码,让记录实时显示。procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);begin edit1.Text := (sender as TDataSource).DataSet.FieldByName('username').AsString; edit2.Text := (sender as TDataSource).DataSet.FieldByName('passwd').AsStringend;楼上给的就可以了 Textradevices怎么把reportbuilder导成excel? ONCONNECT事件应该怎么写 ADVStringGrid、DBADVStringGrid如何设置点击标题列自动排序 哪儿有DELPHI6 RTL UPDATE2 下载? 救命啊,我的声卡出不了声 一个石破天惊的问题 --------------什么是RPC占位程序版本不兼容--- 紧急切磋,先付100分不够再加 为什么我的多线程程序一个一个运行? 如何做一个完全没有Form窗口边框的delphi应用程序?而程序中又要用到Active控件。 二进制数据写入数据库的方法.. 关于程序被系统回收的问题,高手进来指点下
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOTable1: TADOTable;
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Edit3: TEdit;
procedure DataSource1DataChange(Sender: TObject; Field: TField);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin edit1.Text := (sender as TDataSource).DataSet.FieldByName('username').AsString;
edit2.Text := (sender as TDataSource).DataSet.FieldByName('passwd').AsString
end;procedure TForm1.Button1Click(Sender: TObject);
begin
with adotable1 do
begin
if not Active then
Active := true;
edit;
FieldByName('passwd').Value := Edit3.Text;
Post;
end;
end;end.窗体文件如下:
object Form1: TForm1
Left = 192
Top = 110
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 330
Width = 688
Height = 120
Align = alBottom
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Edit1: TEdit
Left = 40
Top = 32
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit1'
end
object Button1: TButton
Left = 240
Top = 144
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 2
OnClick = Button1Click
end
object Edit2: TEdit
Left = 40
Top = 64
Width = 121
Height = 21
TabOrder = 3
Text = 'Edit2'
end
object Edit3: TEdit
Left = 40
Top = 96
Width = 121
Height = 21
TabOrder = 4
Text = 'Edit3'
end
object DataSource1: TDataSource
AutoEdit = False
DataSet = ADOTable1
OnDataChange = DataSource1DataChange
Left = 216
Top = 48
end
object ADOTable1: TADOTable
Active = True
ConnectionString =
'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' +
'fo=False;Initial Catalog=**;Data Source=.'
CursorType = ctStatic
TableName = 'userInfotb'
Left = 296
Top = 56
end
end
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
edit1.Text := (sender as TDataSource).DataSet.FieldByName('username').AsString;
edit2.Text := (sender as TDataSource).DataSet.FieldByName('passwd').AsString
end;楼上给的就可以了