Link to home
Create AccountLog in
Avatar of Netlink2
Netlink2

asked on

How to create an ado control

Hi, I want to use the following code, but I get an error "SqlConnection is not defined".  

 Private Sub CopyTable( _
            ByVal conn As SqlConnection, _
            ByVal sourceTableName As String, _
            ByVal targetTableName As String)

        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If

        Dim sqlCmd As New SqlCommand("INSERT TargetTable SELECT * FROM SourceTable", conn)
        sqlCmd.ExecuteNonQuery()
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Praveen Kumar
Praveen Kumar
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Netlink2
Netlink2

ASKER

Thanks for that, I'll try it.
I get the exact same message when I tried that code.

"SqlConnection is not defined".  
OK, I put

Imports System.Data
Imports System.Data.SqlClient

at the top of the code, now I get a new error

keyword not supported 'provider'

This is using

Dim conn As New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Alcis\Mick.mdb")

Figured that one out too, SqlConnection only works with SQL and doesn't work with Access or DSN.