Datatables headers


Scenario:-I am writing a datable in the SQL server databse.My dt has one column “Employee Name” whici I cant change.

Now,if in my database table I create a coulmn “Employee Name” I am not able to write the data.

Datatable header Database table column result
Employee Name Employee Name Failure
EmployeeName EmployeeName Success
Employee Name EmployeeName Failure
EmployeeName Employee Name Failure

So only when datatable header and database table column matches and doesnt have any space between “Emploee” and “Name” then only it is writing in database.

I am creating the dt from excel and I cant change excel headers.

Is there any way to accomplish this? Can we remove spaces between “Employee” and “Name” from headers or any other approach?

Pulkit Gupta


Did you try changing the data table column name before writing into SQL database?
dataTable.Columns[“Employee Name”].ColumnName = “EmployeeName”

Is it possible to write the entire datatable at once to Database? or are you reading the Datatable here in a for each and then passing each column value repsectively?