The following is the complete coding for moving data from sql to access,
I get an error saying that Microsoft JET Database Engine missing (;) at the end of sql statement!!!! Could you tell me what I am doing wrong?
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
Thanks
Bob Ghodsi