Your stored procedure,
USP_Report, is returning two columns called "Client Meeting ID".
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;
columnName = rawColumnName + " (" + duplicateCount + ")";
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
to send it to the user.
The problem is that the
is being stored in a
field. That means the every
request from every
user is going to be manipulating the same
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.
field, and use a local variable instead. You'll need to pass it into the
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.)