954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to import data from sql to ms access in vb.net through coding

Hi folks:
I get the following error when I try to convert sql to access:
Microsoft JET Database Engine missing (;) at end of sql statement. The first part works fine but I get the error running second part.

Below is the complete coding in vb.net for data transfer.

Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class frmMain
    Inherits System.Windows.Forms.Form
    Private cnn As New SqlConnection
    Private cmd As New SqlCommand
    Private ConnectionString As String
    Private sql As String
    Private str As String
    Private cmdd As New OleDbCommand
    Private iCount As Integer




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ConnectionString = "Server=hp;database=library;integrated security=SSPI;"

        MessageBox.Show("Connection established")

        sql = "SELECT snippetID, snippetName, snippetSource, snippetCode FROM snippet"
        Try
            cnn = New SqlConnection(ConnectionString)


            cnn.Open()
            cmd = New SqlCommand(sql, cnn)
            cmd.ExecuteNonQuery()

            cnn.Close()
            MsgBox("ExecutionNonQuery in SqlCommand executed")

        Catch ex As Exception
            MsgBox("Can not open the connection")
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\tmp\lib.mdb")
            cn.Open()

            str = "insert into snip(snipID, snipName, snipSource, snipCode) values (@snipID, @snipName, " _
           & "@snipSource, @snipCode)IN 'c:\tmp\snip.mdb'"


            cmdd = New OleDbCommand(str, cn)
            iCount = cmdd.ExecuteNonQuery
            cn = Nothing
            MessageBox.Show(iCount)


        Catch ex As Exception

            '  MsgBox("Error:  " & ex.Source & "  " & ex.Message)

        End Try

    End Sub
End Class
bghodsi
Newbie Poster
7 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: