code=Delphi(Pascal)]function SQLServerDataSource.ExecuteQuery(sql : string) : TStringList;
var data : TStringList;
cmd : TADOCommand;
recordSet : _Recordset;
i : Integer;
begin
CoInitialize(nil);
try
cmd := TADOCommand.Create(nil);
cmd.Connection := _connection;
cmd.CommandType := cmdText;
cmd.CommandText := sql; data := TStringList.Create;
recordSet := cmd.Execute;
if (not recordSet.EOF) and (not recordSet.BOF) then
begin
recordSet.MoveFirst;
for i := 1 to recordSet.Fields.Count do
begin
recordSet.Fields.Item[i].Value;
end;
end; finally
ReleaseCon(_connection);
end;
CoUninitialize();
Result := data;
end;[/code]
不知为什么一执行到cmd.Connection := _connection;这里就报Access violation 错,_connection已经连上数据库,并且是已经打开的了.
var data : TStringList;
cmd : TADOCommand;
recordSet : _Recordset;
i : Integer;
begin
CoInitialize(nil);
try
cmd := TADOCommand.Create(nil);
cmd.Connection := _connection;
cmd.CommandType := cmdText;
cmd.CommandText := sql; data := TStringList.Create;
recordSet := cmd.Execute;
if (not recordSet.EOF) and (not recordSet.BOF) then
begin
recordSet.MoveFirst;
for i := 1 to recordSet.Fields.Count do
begin
recordSet.Fields.Item[i].Value;
end;
end; finally
ReleaseCon(_connection);
end;
CoUninitialize();
Result := data;
end;[/code]
不知为什么一执行到cmd.Connection := _connection;这里就报Access violation 错,_connection已经连上数据库,并且是已经打开的了.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货