I'm trying to write Excel application-level add-in. It makes SQL query to the database and populates worksheet with its results. I thought, it should be simple... But not. Is there any way to insert DataTable into excel worksheet? Something like this:
using (SqlConnection connection = new SqlConnection(connectionString))
{
string cmdString = "SELECT * FROM [Table];" // Simplifyed query, in my add-in I need to JOIN 3 tables
SqlCommand cmd = new SqlCommand(cmdString, connection);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
// What I need to write here to insert my DataTable contents into worksheet?
}
Maybe, I should use another approach (not DataTable)? However, my query can return up to 100000 rows of data with 4 columns. So, cell-by-cell pasting will not work, I think.