直接导出
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();

解决方案 »

  1.   

    晕倒忘了注明:windows FORM
      

  2.   

    http://www.csdn.net/develop/read_article.asp?id=18623
      

  3.   

    李大侠,我看过你的很多文章!景仰得很!
    我在企业管理器中执行下面这句:
    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>