为什么我在查询分析器能够执行的语句,到了转换成ADOcommand.text时不能执行呢?(30分)

K

kk2000

Unregistered / Unconfirmed
GUEST, unregistred user!
Master..xp_cmdShell 'isqlw /U sa /d Master /i E:/sjk/sql/ff.sql/o RunResult.Txt'
我总是遇到这种情况,就是不会转换成到客户端的写法!
转换这些字符有什么规律吗?如上面的语句怎么样才
能转换成ADOcommand.text的内容,然后执行Adocommand.execute;
 
怎么没有人!自己顶!
 
ParamCheck = False
 
str:='master.dbo.xp_cmdshell' + 'isqlw /U ' +pchar(edit1.text) + ' /d master ' + '/i' +quotedstr('E:/sjk/sql/ff.sql')+'/o runresult.txt';
Adocom.CommandText:=str;
adocom.ParamCheck:=false;
Adocom.Execute;
这样能编译通过,但执行是说'/'附近有语法错误.
 
估计错在 pchar(edit1.text) 这块,你再调整一下吧
 
str:='master.dbo.xp_cmdshell' + 'isqlw /U ' +quotedstr(edit1.text) + ' /d master ' + '/i' +quotedstr('E:/sjk/sql/ff.sql')+'/o runresult.txt';
我改成这样还是不行的?
 
这还是个字符串的问题,因为xp_cmdshell 后面的参数是字符串。你试一试这样行不!

str:='master.dbo.xp_cmdshell'+''' + 'isqlw /U ' +quotedstr(edit1.text) + ' /d master ' + '/i' +quotedstr('E:/sjk/sql/ff.sql')+'/o runresult.txt'+''';
 
是啊,字符串的问题
 
procedure TForm1.Button2Click(Sender: TObject);
var
str : string;
begin
str := 'xp_cmdShell ''isqlw /U '+Edit1.Text+' /d Master /i '+ Edit2.Text +'/o RunResult.Txt''';
ADOCommand1.CommandText := str;
ADOCommand1.ParamCheck := False;
ADOCommand1.Execute ;
end;
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
ADOCommand1: TADOCommand;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
str:string;
begin
str:= format('DECLARE @cmd sysname'#13#10'SET @cmd = ''dir %s > c:/2.txt'' '#13#10'EXEC master..xp_cmdshell @cmd',['c:']);
showmessage(str);
ADOCommand1.CommandText:=str;
ADOCommand1.Execute;
end;

end.

object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
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 BitBtn1: TBitBtn
Left = 200
Top = 200
Width = 75
Height = 25
Caption = 'BitBtn1'
TabOrder = 0
OnClick = BitBtn1Click
end
object ADOCommand1: TADOCommand
ConnectionString =
'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initi' +
'al Catalog=LCIS2.0'
Parameters = <>
ParamCheck = False
Left = 152
Top = 104
end
end
 
xp_cmdShell
要用
DECLARE @cmd sysname 来做
 
真不好意思! 刚才我的机器掉线。谢谢了!
各位辛苦了! 分不多。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
824
import
I
I
回复
0
查看
590
import
I
I
回复
0
查看
666
import
I
顶部