delphi程序改错!

来源:百度知道 编辑:UC知道 时间:2024/04/28 15:21:27
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var str:String;
begin
ADOQuery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=学生成绩;Data Source=GAOHAOLIANG';
ADOQuery1.SQL:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=学生成绩;Data Source=GAOHAOLIANG';
ADOQuery1.ExecSQL;

如果是查询数据库,你那个语句是不对的,如果你是查询 学生成绩 这个表,应该是这个语句:'select * from 学生成绩'

另外,按照严格来说,你应该如下这么写代码:

ADOQuery1.close;
ADOQuery1.SQL.Clear;//清空sql
ADOQuery1.sql.add('select * from 学生成绩');
ADOQuery1.ExecSQL;

如果按照你那样写,查询语句的话,你第二次点击BUTTON的时候 就会报错了

ADOQuery1.SQL:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=学生成绩;Data Source=GAOHAOLIANG';
这句你是不是写错了?
这里应该写SQL语句比如:ADOQuery1.sql.add('select * from 学生成绩');

ADOQuery1.open;