Your stored procedure, USP_Report
, is returning two columns called "Client Meeting ID".
A DataTable
cannot contain two columns with the same name.
Fix your stored procedure so that the returned column names are unique.
Or fix your code to check for duplicate columns and rename them if necessary:
foreach (DataRow drow in dtSchema.Rows)
{
string rawColumnName = Convert.ToString(drow["ColumnName"]);
int duplicateCount = 1;
string columnName = rawColumnName;
while (ResultsData1.Columns.Contains(columnName))
{
columnName = rawColumnName + " (" + duplicateCount + ")";
duplicateCount++;
}
...
NB: You're also going to run into problems if multiple users try to export the data at the same time, since all requests will be trying to write to the same file. You could end up with the file disappearing, or data from different users' requests getting mixed up in the same file.
You should see if there's an option to create the file in memory, without saving it to disk. If there isn't, then you should use a random file for each user, and be sure to delete it after using
TransmitFile
/
WriteFile
to send it to the user.
EDIT: The problem is that the
DataTable
is being stored in a
static
field. That means the
every request from
every user is going to be manipulating the same
DataTable
instance. With multiple users accessing the site at the same time, you're likely to get much more obscure and confusing errors, as users' changes overwrite each other.
Remove the
static
field, and use a local variable instead. You'll need to pass it into the
ExportToOxml
method as a parameter.
private static void ExportToOxml(bool firstTime, DataTable ResultsData1)
{
...
}
protected void btnmeeting_Click(object sender, EventArgs e)
{
DataTable ResultsData1 = new DataTable();
...
}
(The comment about the file name conflicts still stands.)