delphi怎么将ADOQuery1写在function里面而且有参数,参数就是传入sql语句返回的是integer
unitclass1;interfaceusesDB,ADODB;functionfangfa2(sql:string):integer;implementationus...
unit class1;
interface
uses
DB, ADODB;
function fangfa2(sql:string):integer;
implementation
uses SysUtils;
function fangfa2(sql:string):integer;
var
str:string;
ADOQuery1: TADOQuery;
begin
//这是连接字符串
str:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ss;Data Source=WIN-LIZHENJUN';
ADOQuery1.ConnectionString:=str;
//关闭数据库 ---执行的时候在这里开始出错
ADOQuery1.Close;
//清空数据库
ADOQuery1.SQL.Clear;
//执行查询语句
ADOQuery1.SQL.Add(sql);
//打开数据库
ADOQuery1.Open;
//返回数据的条数
Result:= ADOQuery1.RecordCount;
end;
end. 展开
interface
uses
DB, ADODB;
function fangfa2(sql:string):integer;
implementation
uses SysUtils;
function fangfa2(sql:string):integer;
var
str:string;
ADOQuery1: TADOQuery;
begin
//这是连接字符串
str:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ss;Data Source=WIN-LIZHENJUN';
ADOQuery1.ConnectionString:=str;
//关闭数据库 ---执行的时候在这里开始出错
ADOQuery1.Close;
//清空数据库
ADOQuery1.SQL.Clear;
//执行查询语句
ADOQuery1.SQL.Add(sql);
//打开数据库
ADOQuery1.Open;
//返回数据的条数
Result:= ADOQuery1.RecordCount;
end;
end. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询