我在mainform上有个Tdatabase,readonly设的否,然后在另一个from中加了一个Tquery,我用SQL查找后,想修改数据集:
query1.edit;
修改语句;
query1.post;
query1.close;
但是运行的时候他说,Tquery:啥子a read-only dataset,不能修改。请问哪错了啊?怎样改成不是read-only啊?
query1.edit;
修改语句;
query1.post;
query1.close;
但是运行的时候他说,Tquery:啥子a read-only dataset,不能修改。请问哪错了啊?怎样改成不是read-only啊?
Tquery没有readonly的属性啊,sql里也没有静态语句了。
Tquery不支持edit啊?用sql怎样做啊?
你用sql语句update吧
query1.close;
query1.sql.clear;
query1.sql.add('.........');
query1.aql.add('.......');
query1.open;
应该没有用多表操作吧
很好用的。
或直接用Update SQL语句
Query支持Edit呀,我一直在用的
Query支持数据集更新很有限得, 我一般用table
// 文件名:DBOperate.pas
//
// 类名:数据库操作类
// 描述:用于实现数据库的基本操作功能
//
// 作者:Win Lai
// 创建日期:2003-12-11
// 修改日期:2003-12-18
//
// 在Delphi6.0编译通过
//
// 使用:
//
// 1.定义类对象。
// MyClass : TDBOperate;
//
// 2.分配空间给类对象。
// MyClass := TDBOperate.Create(nil);
//
// 3.建立数据库链接。
// MyClass.ConnectionStrings := '[数据库链接串]'
// MyClass.Connect
//
// 4.操作数据库。
// MyClass.SQLStrings := '[SQL语句]'
// MyClass.SQLExec
// MyClass.SQLOpen
//
// 5.链接数据库控件。
// MyClass.DataSource.DateSet := MyClass.ADOTable;
// [数据库控件].DataSource := MyClass.DataSource;
//
// 6.释放类对象。
// MyClass.Free;
//
//-------------------------------------------------------------------------unit DBOperate;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ADODB, DB;type
TDBOperate = class(TObject) private
FADOConnection: TADOConnection;
FADOQuery: TADOQuery;
FADOTable: TADOTable;
FDataSource: TDataSource; FConnectionStrings: string;
FSQLStrings: string;
protected public
constructor Create(AOwner: TComponent); virtual;
destructor Destroy; override; procedure Connect;
procedure SQLExec;
procedure SQLOpen; function Disconnect: boolean;
function IsConnected: boolean; property ADOConnection: TADOConnection read FADOConnection write FADOConnection;
property ADOQuery: TADOQuery read FADOQuery write FADOQuery;
property ADOTable: TADOTable read FADOTable write FADOTable;
property DataSource: TDataSource read FDataSource write FDataSource;
property ConnectionStrings: string read FConnectionStrings write FConnectionStrings;
property SQLStrings: string read FSQLStrings write FSQLStrings;
end;implementation//-------------------------------------------------------------------------
// 构造函数
constructor TDBOperate.Create(AOwner: TComponent);
begin
inherited Create();
//..
FADOConnection := TADOConnection.Create(nil);
FADOQuery := TADOQuery.Create(nil);
FADOTable := TADOTable.Create(nil);
FDataSource := TDataSource.Create(nil); FADOConnection.LoginPrompt := false; // 不显示登录框
end;//-------------------------------------------------------------------------
// 析构函数
destructor TDBOperate.Destroy;
begin
//..
Disconnect;
FADOConnection.Free;
FADOQuery.Free;
FADOTable.Free;
FDataSource.Free; inherited Destroy;
end;//-------------------------------------------------------------------------
// 链接数据库
procedure TDBOperate.Connect;
begin
// 已经链接
if IsConnected=true then
begin
exit
end; try
FADOQuery.Connection := FADOConnection;
FADOTable.Connection := FADOConnection; FADOConnection.Close;
FADOConnection.ConnectionString := FConnectionStrings;
FADOConnection.Open; if FADOConnection.Connected = false then
begin
// 链接数据库失败
Application.MessageBox('链接数据库失败!', '错误', MB_OK OR MB_ICONERROR);
Application.Terminate;
end;
except
Application.MessageBox('链接数据库失败!', '错误', MB_OK OR MB_ICONERROR);
Application.Terminate;
end;
end;//-------------------------------------------------------------------------
// 断开链接数据库
function TDBOperate.Disconnect: boolean;
begin
// 已经断开链接
if IsConnected=false then
begin
Result := true;
exit;
end; try
FADOConnection.Close;
Result := true;
except
Result := false;
end;
end;//-------------------------------------------------------------------------
// 检查是否链接数据库
function TDBOperate.IsConnected: boolean;
begin
if ADOConnection.Connected = false then
Result := false
else
Result := true;
end;//-------------------------------------------------------------------------
// 执行SQL语句,不返回数据集
procedure TDBOperate.SQLExec;
begin
FADOQuery.Close;
FADOQuery.SQL.Text := FSQLStrings;
FADOQuery.ExecSQL;
end;//-------------------------------------------------------------------------
// 执行SQL语句,可返回数据集
procedure TDBOperate.SQLOpen;
begin
FADOQuery.Close;
FADOQuery.SQL.Text := FSQLStrings;
FADOQuery.Open;
end;//-------------------------------------------------------------------------
end.