G
Guest
Hi All
I am reading data from excel file and storing it into existing table in sql server. If there are new columns in the excel file I want to add new columns in the table dynamically. I am doing followin
• reading data of excel file into excelDataSet.table
• loading Schema of the table into sqlDataset.table
• finding out any new columns in the excel file and then adding columns in table2 of sqlDataSet as follo
•
For Each excelColumn In excelDataSet.Tables(table1).Column
Dim allStockColumns As DataColumnCollection = sqlDataSet.Tables(table2).Column
Dim findThisColumn(0) As Objec
findThisColumn(0) = Trim(excelColumn.ColumnName
Tr
If Not (allStockColumns Is Nothing) The
If Not (allStockColumns.Contains(findThisColumn(0))) The
'column is missing so add i
Dim myColumn = New DataColumn(Trim(excelColumn.ColumnName)
myColumn.DataType = allStockColumns(1).DataType(
myColumn.AllowDBNull = Tru
sqlDataSet.Tables(table2).Columns.Add(myColumn
End I
End I
Catch ex As Exceptio
logWriter.WriteLine(ex.Message
End Tr
This code segment adds new column in the table2 of the sqlDataSet but it doesn’t update table in the database. How can I update schema of the table in the database
Thanks for help
I am reading data from excel file and storing it into existing table in sql server. If there are new columns in the excel file I want to add new columns in the table dynamically. I am doing followin
• reading data of excel file into excelDataSet.table
• loading Schema of the table into sqlDataset.table
• finding out any new columns in the excel file and then adding columns in table2 of sqlDataSet as follo
•
For Each excelColumn In excelDataSet.Tables(table1).Column
Dim allStockColumns As DataColumnCollection = sqlDataSet.Tables(table2).Column
Dim findThisColumn(0) As Objec
findThisColumn(0) = Trim(excelColumn.ColumnName
Tr
If Not (allStockColumns Is Nothing) The
If Not (allStockColumns.Contains(findThisColumn(0))) The
'column is missing so add i
Dim myColumn = New DataColumn(Trim(excelColumn.ColumnName)
myColumn.DataType = allStockColumns(1).DataType(
myColumn.AllowDBNull = Tru
sqlDataSet.Tables(table2).Columns.Add(myColumn
End I
End I
Catch ex As Exceptio
logWriter.WriteLine(ex.Message
End Tr
This code segment adds new column in the table2 of the sqlDataSet but it doesn’t update table in the database. How can I update schema of the table in the database
Thanks for help