In a folder C:\\Excel
, I have these files:
Schema.ini
contains:
[test.csv]
Format=Delimited(;)
ColNameHeader=True
MaxScanRows=2
CharacterSet=ANSI
DecimalSymbol=,
Col1=Lot Char
Col2=dateResa1 Date
Col3=PRIXLOG_IMMO Double
Col4=MONTANT_CA_ESTIME Double
And in MS Access, I have an export routine which loads csv file data into a created table : TEST
Private Sub importCSV_Click()
Dim strSQL As String
On Error Resume Next: DoCmd.DeleteObject acTable, "TEST": On Error GoTo 0
strSQL = " SELECT CStr(t.lot), CDate(t.dateResa1), CDbl(t.PRIXLOG_IMMO), CDbl(t.MONTANT_CA_ESTIME) " & _
" INTO TEST " & _
" FROM [Text;FMT=Delimited;HDR=YES;CharacterSet=ANSI;DATABASE=C:\Excel].[test.csv] t"
CurrentDb.Execute strSQL
End Sub
It works great but the column names of the table MS-Access TEST are named:
Is there a way to force the name of columns table TEST by using only SQL and Schema.ini
?
Solution:
Because I casted the fields with CStr, CDate..., field names must be redefined with an alias and Icing on the cake, alias can be as same as field name. I tested it
为了避免在Access SQL中强制转换字段,在Schema.ini中为每个列声明类型就足够了,并允许在Access查询中使用*!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.