i want to create a table from the excel file (excel file has header).
the problem is that the type is always string for all , the table don't give the right format for date type.
this is my code :
Dim table As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames)
sqlsc = "CREATE TABLE " + tableName + "([Id] [int] IDENTITY(1,1) NOT NULL ,"
Dim i As Integer = 0
While i < table.Columns.Count
Dim columname = Regex.Replace(table.Columns(i).ColumnName.ToUpper, "[^A-Za-z0-9\-/]", "")
sqlsc += vbLf & " [" + columname + "] "
Dim columnType As String = table.Columns(i).DataType.ToString()
If table.Columns(i).AutoIncrement Then
sqlsc &= " IDENTITY(" + table.Columns(i).AutoIncrementSeed.ToString() + "," + table.Columns(i).AutoIncrementStep.ToString() + ") "
End If
Select Case columnType
Case "System.Int32"
sqlsc &= " int "
Case "System.Int64"
sqlsc &= " bigint "
Case "System.Int16"
sqlsc &= " smallint"
Case "System.Byte"
sqlsc &= " tinyint"
Case "System.Decimal"
sqlsc &= " decimal "
Case "System.DateTime"
sqlsc &= " datetime "
Case "System.String"
sqlsc += String.Format(" nvarchar({0}) ", If(table.Columns(i).MaxLength = -1, "max", table.Columns(i).MaxLength.ToString()))
End Select
'End If
sqlsc &= ","
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While