Create Table With Parameters
I would like to create an Excel table, using OleDb: OleDbCommand oleDbCommand = new OleDbCommand(); oleDbCommand.Connection = oleDbConnection; String commandText = 'CREATE TABLE'
Solution 1:
As learningNew stated, you're just providing @var+(index + 1) inside your loop as the column headers.
To correct this, you could include an switch condition to provide the actual column header based on the current iteration cycle.
To do so, change the line
oleDbCommand.Parameters.Add(new OleDbParameter("@var" + (index + 1).ToString(), _header));
to something like this (untested):
string colHeader = string.Empty; // variable for the column header
switch (index)
{
case 0:
colHeader = "Preis/Stk. EURO";
case 1:
colHeader = "Stk.";
case 2:
colHeader = "Produkt";
default:
break;
}
// using the string variable here to set the actual column header
oleDbCommand.Parameters.Add(new OleDbParameter(colHeader, _header));
Solution 2:
1) I created a table with the columns Name: F1, F2, ...
2) I Updated the columns Name with a dynamic Name (F1, F2, ... also created dynamicly)
String _Header = "PREIS/Stk. EURO"
oleDbCommand.CommandText = "UPDATE[MySheet] SET F1 = @var";
oleDbCommand.Parameters.Add(new OleDbParameter("@var", _header));
That's all!
Post a Comment for "Create Table With Parameters"