我想通过ODBC从Access到SQLite导入数据(非结构) 可以,但是有一点很烦人:
我不想自动创建新表-我想将数据导入到现有表中,但出现以下错误:
ODBC--call failed
table "x" already exists(1)(#1)
我想找到一种避免在sqlite中创建新表的方法。
我还尝试了另一种解决方案,用于通过csv从Access到SQLite导入数据。但是,我的编码是utf-8,但它会将数据显示为问号!
答案 0 :(得分:0)
有多种方法可以使用Access移动数据。
将数据追加到ODBC表时,建议执行以下步骤:
或者,Access可以直接对ODBC数据源运行追加查询,而无需创建链接表,但这需要一些SQL知识。语法如下:
INSERT INTO [ODBC;MyDSNOrConnectionString].[MyRemoteTable] (Field1, Field2, FieldN)
SELECT Field1, Field2, FieldN
FROM MyLocalTable
答案 1 :(得分:0)
如果两侧的表具有相同的名称和结构,并且表结构存储在系统表中,则还有另一种通过Adobe连接将Access表记录导出到现有ODBC表中的方法。
Dim Str_Sql As String
Dim Conn As New ADODB.Connection
Dim myDSN As String
Dim UserName As String
Dim Password As String
Dim Rs_Tabl As DAO.Recordset
Dim Rs_TablStru As DAO.Recordset
myDSN = ...
UserName = ...
Password = ...
Conn.Open "dsn=" & myDSN & ";uid=" & UserName & ";pwd=" & Password
Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = Conn
Set Rs_Tabl = CurrentDb.OpenRecordset(TablName)
Set Rs_TablStru = CurrentDb.OpenRecordset("select * from Systable where TableName=TableName order by ColumnOrder")
Str_Sql = "truncate table TableName"
Conn.Execute (Str_Sql)
Str_Sql = "insert into TableName values ('"
Do Until Rs_Tabl.EOF
Str_Sql = "insert into TableName values ('"
Rs_TablStru.MoveFirst
Do Until Rs_TablStru.EOF
Str_Sql = Str_Sql & Rs_Tabl.Fields(Rs_TablStru.Fields("AAA")) & "','"
Rs_TablStru.MoveNext
Loop
Str_Sql = Mid(Str_Sql, 1, Len(Str_Sql) - 2) & ")"
Debug.Print Str_Sql
Conn.Execute (Str_Sql)
Rs_Tabl.MoveNext
Loop
Rs_Tabl.Close
Rs_TablStru.Close
Set Rs_Tabl = Nothing
Set Rs_TablStru = Nothing
Conn.Close
* AAA:系统表中的一列,用于存储所有表中的列名。