Table from SQL to MSAccess

danasegarane

Active member
Joined
Jun 14, 2006
Messages
41
Programming Experience
Beginner
Dear All,
I am using this code to insert table to MSAccess from SQL.But it is not producing any data in the Access table.Can some body help
VB.NET:
Private Sub FillAccesstables(ByVal sTablename As String)
        Dim sqltemptable As DataTable 'sql temp table
        Dim datemptable As DataTable    'access temp table
        Dim sqlcmdtext As SqlCommand
        Dim dacmdtext As OleDbCommand
        Dim sqltemp As String = String.Empty
        Dim oletemp As String = String.Empty
        sqltemp = "Select * from " & sTablename
        sqlcmdtext = New SqlCommand(sqltemp, con)
        dacmdtext = New OleDbCommand(sqltemp, AccessOledbCon)
        SQLAdapter = New SqlDataAdapter(sqlcmdtext)
        SQLAdapter.AcceptChangesDuringFill = False
        sqltemptable = New DataTable
        datemptable = New DataTable
        SQLAdapter.Fill(sqltemptable)
        OLAdapter = New OleDbDataAdapter(dacmdtext)
        OLAdapter.Fill(datemptable)
        OLAdapter.AcceptChangesDuringFill = True
        SQLAdapter.Update(datemptable)

    End Sub
 
it would be much easier if you just linked the access database to your sql server, and issued the command:

INSERT INTO accessdatabase.destinationtablename SELECT * from dbo.sourcetablename
 
In SQL Server management console, expand the tree to reveal the place where you make odbc connections to other databases, and get SQL Server itself to connec tto the access database
 
Back
Top