如题。
VS2005编写的网站,要求实现这样的功能,具体步骤如何?能否实现导出文件加密?

解决方案 »

  1.   

    这个功能用编程肯定是能实现,但用数据库本身的命令速度和效率肯定更高如果是SQL Server ,楼主可以google一下bcp命令
      

  2.   

    可以先把数据绑定到gridview控件上,然后再把数据用Excel文件的形式导出来,网上有例子的
      

  3.   

    要求是点击一个按钮,然后把纪录导出,这个按钮事件里能调用“bcp命令”吗?
      

  4.   

    应该可以,使用 System.Diagnostics.Process.Start(@"某路径下的\bcp ...详细指令");
      

  5.   

    “某路径下的\bcp ...详细指令”这个是如何写的?
      

  6.   

    可以的,导出成CSV格式............................具体做法要搜搜....很早以前做过.
      

  7.   

    bcp "select * from database_name.dbo.userproduct" queryout "D:\Documents and Settings\Administrator\桌面\2008-6-7.xls" -c -q -S"server_name" -U"sa" -P"***"//ORbcp "database_name.dbo.userproduct" out "D:\Documents and Settings\Administrator\桌面\2008-6-7.xls" -c -q -S"server_name" -U"sa" -P"***"
      

  8.   

    谢谢ls的回答。现在直接在查询分析器里可以用“bcp”了。
    但是在程序里还是不行啊,
    string sql = "EXEC master..xp_cmdshell 'bcp [xxx].[dbo].userproduct out d:\\DT1.txt -c -S -Usa -P'";        //下面是执行查询部分
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["webCon"].ConnectionString);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
    conn.Close();
    执行后不报错,但“DT1.txt”里没纪录。
    另外
    如果导出成“.xls”文件,日期和原来不同了。如数据库里日期“2008-5-7”在导出文件里就成了“0:00:00”。
    求解。
      

  9.   

    这个应该不是DML语句,不能用CMD,你用启用进程bcp试试?lz问的问题都不错,都是我不会的.谢谢了.
      

  10.   

    System.Diagnostics.Process.Start这个应该可以调用BCP命令啊.
      

  11.   

    有一个比较简单的方法,我一直在用
    思路是这样的1、将 GridView 的内容变成字串
    2、将上述字串变成 Steam 流提供给用户下载
    3、文件名称可以是 .htm 或者是 .xls(Excel 可以打开 HTML)上述功能,实际上是我把页面所看到的报表,用文件下载的形式让用户保存
    因为这不是我的电脑,没有代码贴给你看
      

  12.   

    现在搞得可以导出xls文件了。日期格式也对,但是一条纪录都写在一个单元格里了。而且导回数据库报“找不到可安装的isam”的错。
    再次求解。

    “有一个比较简单的方法,我一直在用 
    思路是这样的 1、将 GridView 的内容变成字串 
    2、将上述字串变成 Steam 流提供给用户下载 
    3、文件名称可以是 .htm 或者是 .xls(Excel 可以打开 HTML) 

    这个方法搞得文件导回数据库报“外部表不是预期的格式”的错误。
      

  13.   

    现在用{
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["webCon"].ConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = sqlConn;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sqlConn.Open();
            cmd.CommandText = "Select * from userproduct1";
            DataSet ds = new DataSet();
            sda.Fill(ds);        if (ds.Tables[0].Rows.Count > 0)
            {
                string BcpExec = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//循环取本地文件名
                {
                    BcpExec = @"bcp  [cangku].[dbo].userproduct1 out d:\\DT1.xls";
                    //BcpExec += ds.Tables[0].Rows[i]["path"].ToString();
                    BcpExec += " -S -Usa -P -c -t,";//组合bcp命令
                    //Response.Write();//执行bcp命令并显示操作结果
                    ExeCommand(BcpExec);
                    
                }
                Response.Write("共" + ds.Tables[0].Rows.Count + "条数据导出成功!");
            }
        }    /**/
        /// <summary>
        /// 执行Cmd命令
        /// </summary>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static string ExeCommand(string commandText)
        {
            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("exit");
                strOutput = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                p.Close();
            }
            catch (Exception e)
            {
                strOutput = e.Message;
            }
            return strOutput;
        }
    可以