1
Reply

Dataset to Excel for Download

Shawn O

Shawn O

Mar 7 2006 9:27 AM
2.8k
I have been assigned the task to create a web application and collect data from a SQL database. I put this data into a dataset and need to allow the user to 'export' this information in a CSV and a XLS. I have the CSV completed. I need to select certain data from the dataset and put it into different Excel sheets. When i go to write to a row in the excel file, I get a response from Visual Studio that I cannot write to the 'range' due to its protection level. I have pasted some code below. What am I missing?

if (dt1 != null)

{

foreach (DataRow dr in dt1.Rows)

{

foreach (DataColumn dc in dr.Table.Columns)

{

    dataLine = dataLine + dr[dc] + ",";

    }

              dataLine = dataLine.Substring(0, dataLine.Length - 1);

              dataLine = dataLine + "\n";

              ws.Cells.Text = dataLine;

              //((Range)ws.Cells["1", "A"]).Value2 = dataLine; // set the cell value at a row and column

    }

}


Answers (1)