Hello Sir,
i already asked regarding dynamic create table from excel and insert the data.
its working fine but how can i handle if excel header name have space
like First name it create error on generating dynamic query.
Incorrect syntax near 'VARCHAR'.
if (firstRow)
{
query += "IF OBJECT_ID('dbo." + Path.GetFileNameWithoutExtension(file.FileName) + "', 'U') IS NULL ";
query += "BEGIN ";
query += "CREATE TABLE [dbo].[" + Path.GetFileNameWithoutExtension(file.FileName) + "](";
foreach (IXLCell cell in row.Cells())
{
dt.Columns.Add(cell.Value.ToString());
query += cell.Value.ToString() + " VARCHAR(MAX),";
}
firstRow = false;
query = query.TrimEnd(',');
query += ")";
query += " END";
}