title: create csv file from multiple datatables in c#
body: <p>i want to export data from <strong>multiple datatables</strong> to <strong>csv</strong> file.</p>
  
  <p>i already know how to write one datatable to csv.</p>
  
  <p>any help please.
  i have this function </p>
  
  <pre><code> public void CreateCSVFile(DataTable dt, string strFilePath)  
   {  
     try  
     {  
       StreamWriter sw = new StreamWriter(strFilePath, false);  
       int columnCount = dt.Columns.Count;  
       for (int i = 0; i &lt; columnCount ; i++)  
       {  
         sw.Write(dt.Columns[i]);  
         if (i &lt; columnCount - 1)  
         {  
           sw.Write(",");  
         }  
       }  
       sw.Write(sw.NewLine);  
       foreach (DataRow dr in dt.Rows)  
       {  
         for (int i = 0; i &lt; columnCount ; i++)  
         {  
           if (!Convert.IsDBNull(dr[i]))  
           {  
             sw.Write(dr[i].ToString());  
           }  
           if (i &lt; columnCount - 1)  
           {  
             sw.Write(",");  
           }  
         }  
         sw.Write(sw.NewLine);  
       }  
       sw.Close();  
     }  
     catch (Exception ex)  
     {  
       throw ex;  
     }  
   }  
  </code></pre>