procedure TForm1.Button4Click(Sender: TObject);//回传按钮
var
str1,str2:string;
begin
连接到本地数据库;
if (form1.edit23.Text='') or  (form1.edit24.Text='') or (form1.edit26.Text='') then
 showmessage('您输入的信息不全!')
else
with unit4.DataModule4 do
   begin
     adocommand1.CommandText:='exec link :linkmena,:dbna,:loginna,:paw';
     adocommand1.parameters.ParamValues['linkmena']:=trim(form1.edit23.Text);//连接名称
     adocommand1.parameters.ParamValues['dbna']:=trim(form1.edit26.Text);//远程数据库名
     adocommand1.parameters.ParamValues['loginna']:=trim(form1.edit24.Text);//远程登陆名
     adocommand1.parameters.ParamValues['paw']:=trim(form1.edit25.Text);//密码
     adocommand1.Execute;
     str1:=trim(form1.Edit26.Text);
     str2:= trim(form1.edit22.Text);//任意的表名
     adocommand5.CommandText:='insert into test.''+str1+''.dbo.''+str2+'' select * from '''+trim(form1.edit22.Text)+''''; //可能有问题
     adocommand5.execute;
     showmessage('已经成功回传!');
   end;
end;在SQLSERVER中建立了储存过程:link:
CREATE PROCEDURE link @linkmena varchar(30),@dbna varchar(30),@loginna varchar(10),@paw varchar(20)
 AS
exec (' sp_addlinkedserver  ''test'' ,''sqlserver'',''sqloledb'','''+@linkmena+''',null,null,'''+@dbna+'''')
exec ('sp_addlinkedsrvlogin ''test'',''false'',null,'''+@loginna+''','''+@paw+'''')
GO但是delphi提示microsoft ODBC 驱动程序管理器未发现数据源名称并未指定默认驱动程序请各位高手指点!此程序的目的为把本地数据库中的表传到目的数据库中!(目的数据库是局域网内的一台电脑!)

解决方案 »

  1.   

    adocommand5.CommandText:='insert into test.'+str1+'.dbo.'+str2+' select *  from '+trim(form1.edit22.Text); 这样是否可以?
      

  2.   

    何必搞得那么麻烦。
    adocommand5.Connection := 后
    adocommand5.CommandText:='insert into .计算机名'+数据库名+'.dbo.'+表名+' select *  from '+trim(form1.edit22.Text);
      

  3.   

    adocommand5.CommandText:='insert into .计算机名'+数据库名+'.dbo.'+表名+' select * from '+trim(form1.edit22.Text);
    怎么计算机名前加'.'?
    在不在????
      

  4.   

    adocommand5.CommandText:='insert into test.''+str1+''.dbo.''+str2+'' select * from '''+trim(form1.edit22.Text)+''''; //可能有问题在这句代码之后,你加一句
    showmessage(adocommand5.CommandText);
    看一看出来的SQL语句是不是能够在“查询分析器”中正确执行吗?
      

  5.   

    adocommand5.Connection应该是连到远程计算机上,
      

  6.   

    应在查询分析器调试过关再执行............
    adocommand5.CommandText:='insert into .计算机名'+数据库名+'.dbo.'+表名+' select * from '+trim(form1.edit22.Text);
    好像还不行,要对另一台机子登陆成功以后才行,少了登陆语句
      

  7.   

    我现在先登陆到另一台机子后,再执行link储存过程,再执行insert into语句,delphi报错说:
    系统无法再sysservers中找到mlb server,但是再sysservers中我找到了mlb (远程计算机名)
    ?这是怎么回事?
    请教高手!
      

  8.   

    再sql中也是这样!报的错一样!
      

  9.   

    没有语法错误!我在查询分析器中也是这样!
    现在报的还是系统无法再sysservers中找到mlb server,但是再sysservers中我找到了mlb (远程计算机名)
    ?这是怎么回事?