如何将数据从一个数据库表复制到另一个数据库表?

时间:2016-07-30 10:52:33

标签: database vb.net oledb insert-into

我需要帮助我在vb.net中编码,将数据从一个数据库表复制到ms访问数据库中的另一个数据库表。

以下是我的代码:

Dim conn2 As OleDbConnection
   Dim cmd2 As OleDbCommand
   Dim SQLStr2 As String


    conn2 = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= '" & TextBox3.Text & "' ;Jet OLEDB:Database Password=cscfo13poppsi; ")


   SQLStr2 = "SELECT * FROM pop IN '" & TextBox3.Text & "'"
   conn2.Open()
   cmd2 = New OleDbCommand(SQLStr2, conn2)
   cmd2.ExecuteNonQuery()

   Dim conn As OleDbConnection
   Dim cmd As OleDbCommand
   Dim SQLStr1 As String

   conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=psipop.accdb;Jet OLEDB:Database Password=cscfo13poppsi;")
   SQLStr1 = "INSERT INTO pop 'psipop'"
   conn.Open()
   cmd = New OleDbCommand(SQLStr1, conn)
   cmd.ExecuteNonQuery()

错误是“INSERT INTO中的语法错误”

2 个答案:

答案 0 :(得分:0)

INSERT语句的语法错误。试试这个:

Insert Into pop Values('psipop')

答案 1 :(得分:0)

我找到了解决这个问题的方法。它有效!

只需访问此链接:Copy records from one database to another database