C#将数据库里中的数据导到excel中

 private void button1_Click(object sender, EventArgs e)
        {
            //string
            string strsql = "EXEC master..xp_cmdshell 'bcp CorpWant.dbo.TempTree out d:/jxtDemo/Temp.xls -c -q -S. -Usa -Psa123456'";
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa123456;database=CorpWant");
            conn.Open();
            SqlCommand cmd = new SqlCommand(strsql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();

        }

你可能感兴趣的:(C#将数据库里中的数据导到excel中)