调用bcp,网上说可以远程,试了下貌似不行,哎,咋办。

 
  1.  protected void btnimport_Click(object sender, EventArgs e)
  2.     {
  3.         string filepath = FileUpload1.PostedFile.FileName;
  4.         string path=filepath.Remove(filepath.LastIndexOf("//"));
  5.         string filename=FileUpload1.FileName.Trim();
  6.         bool checkspace = path.Contains(" ");
  7.         string extName = "";
  8.         extName = filepath.Substring(filepath.LastIndexOf(".") + 1);//获得文件的扩展名 
  9.         if (extName == "txt")
  10.         {
  11.             string BcpExec = "";
  12.             string BcpExec1 = "";
  13.             if (checkspace)
  14.             {
  15.                 BcpExec = "subst w: /"" + path.Trim() + "/"";
  16.                 BcpExec1 = @"bcp xdcx..BadLoan in w:/" + filename + " ";
  17.             }
  18.             else
  19.             {
  20.                 BcpExec = "cd";
  21.                 BcpExec1 = @"bcp xdcx..BadLoan in "+filepath+"";
  22.             }
  23.             
  24.            
  25.             //BcpExec += ds.Tables[0].Rows[i]["path"].ToString();
  26.             BcpExec1 += " -c -t , -S10.0.74.15 -Usa -P1234";//组合bcp命令
  27.             string msg=ExeCommand(BcpExec, BcpExec1);//执行bcp命令并显示操作结果
  28. private string ExeCommand(string commandText, string commandText1)
  29.     {
  30.         Process p = new Process();
  31.         p.StartInfo.FileName = "cmd.exe";
  32.         p.StartInfo.UseShellExecute = false;
  33.         p.StartInfo.RedirectStandardInput = true;
  34.         p.StartInfo.RedirectStandardOutput = true;
  35.         p.StartInfo.RedirectStandardError = true;
  36.         p.StartInfo.CreateNoWindow = true;
  37.         string strOutput = null;
  38.         try
  39.         {
  40.             p.Start();
  41.             p.StandardInput.WriteLine(commandText);
  42.             p.StandardInput.WriteLine(commandText1);
  43.             p.StandardInput.WriteLine("exit");
  44.             strOutput = p.StandardOutput.ReadToEnd();
  45.             p.WaitForExit();
  46.             p.Close();
  47.         }
  48.         catch (Exception e)
  49.         {
  50.             strOutput = e.Message;
  51.         }
  52.         return strOutput;
  53.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值