您的位置:首页 > 其它

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

2008-10-21 02:01 295 查看
protected void btnimport_Click(object sender, EventArgs e)

{

string filepath = FileUpload1.PostedFile.FileName;

string path=filepath.Remove(filepath.LastIndexOf("//"));

string filename=FileUpload1.FileName.Trim();

bool checkspace = path.Contains(" ");

string extName = "";

extName = filepath.Substring(filepath.LastIndexOf(".") + 1);//获得文件的扩展名

if (extName == "txt")

{

string BcpExec = "";

string BcpExec1 = "";

if (checkspace)

{

BcpExec = "subst w: /"" + path.Trim() + "/"";

BcpExec1 = @"bcp xdcx..BadLoan in w:/" + filename + " ";

}

else

{

BcpExec = "cd";

BcpExec1 = @"bcp xdcx..BadLoan in "+filepath+"";

}

//BcpExec += ds.Tables[0].Rows[i]["path"].ToString();

BcpExec1 += " -c -t , -S10.0.74.15 -Usa -P1234";//组合bcp命令

string msg=ExeCommand(BcpExec, BcpExec1);//执行bcp命令并显示操作结果

private string ExeCommand(string commandText, string commandText1)

{

Process p = new Process();

p.StartInfo.FileName = "cmd.exe";

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardInput = true;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = true;

string strOutput = null;

try

{

p.Start();

p.StandardInput.WriteLine(commandText);

p.StandardInput.WriteLine(commandText1);

p.StandardInput.WriteLine("exit");

strOutput = p.StandardOutput.ReadToEnd();

p.WaitForExit();

p.Close();

}

catch (Exception e)

{

strOutput = e.Message;

}

return strOutput;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐