直接导出
this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls");
this.Page.Response.Charset = "GB2312";
this.Page.Response.ContentEncoding =System.Text.Encoding.Default;
this.Page.Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter textstring = new System.IO.StringWriter();
HtmlTextWriter htmltext = new HtmlTextWriter(textstring);
this.DataGrid1.RenderControl(htmltext);
this.Page.Response.Write(textstring);
this.Page.Response.End();
this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls");
this.Page.Response.Charset = "GB2312";
this.Page.Response.ContentEncoding =System.Text.Encoding.Default;
this.Page.Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter textstring = new System.IO.StringWriter();
HtmlTextWriter htmltext = new HtmlTextWriter(textstring);
this.DataGrid1.RenderControl(htmltext);
this.Page.Response.Write(textstring);
this.Page.Response.End();
我在企业管理器中执行下面这句:
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout C:\authors.xls -c -Sservername -Usa -P'
输出为:
row1:SQLState = 08001, NativeError = 17
row2:Error = [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝
ROW3:SQLState = 01000, NativeError = 53
ROW4:Warning = [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
ROW5:<null>