0

Imports System.Data.SqlServerCe
Public Class SQLCeCon
    Private SQLCeCon As New SqlCeConnection("Data Source=au2015.sdf;Persist Security Info=False;")
    Private SQLCeCmd As SqlCeCommand
    Public SQLCeDA As SqlCeDataAdapter
    Public SQLCeDT As DataTable
    Public Params As New List(Of SqlCeParameter)
    Public RecordCount As Integer
    Public Exception As String

    Public Sub ExecQuery(Query As String)
        'Reset query stats'
        RecordCount = 0
        Exception = ""
        Try
            SQLCeCon.Open()
            SQLCeCmd = New SqlCeConnection(Query, SQLCeCon)
            Params.ForEach(Sub(p) SQLCeCmd.Parameters.Add(p))
            Params.Clear()
            SQLCeDT = New DataTable
            SQLCeDA = New SqlCeDataAdapter(SQLCeCmd)
            RecordCount = SQLCeDA.Fill(SQLCeDT)
        Catch ex As Exception
            Exception = ex.Message
        End Try
        If SQLCeCon.State - ConnectionState.Open Then SQLCeCon.Close()
    End Sub
End Class

I’m receiving an error at New SqlCeConnection(Query, SQLCeCon) which reads “Overload resolution failed because no accessible 'NEW' accepts this number of arguments”. I have no idea what this means my attempts to research the matter haven’t been helpful. I’m new to this forum board and a beginner with vb.net

user3697824
  • 538
  • 4
  • 15
  • The connection doesnt need nor can it use the query. [SqlCeConnection Class](https://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection(v=vs.100).aspx) F1 can be your bestest buddy – Ňɏssa Pøngjǣrdenlarp May 24 '16 at 14:18
  • I should have used SqlCeCommand not SqlCeConnection. Thank you. –  May 24 '16 at 14:42
  • you should also be using `Using` – Ňɏssa Pøngjǣrdenlarp May 24 '16 at 14:45
  • I'm looking into that, although I'm a beginner, so I'm not sure how the using statement applies here or would be preferable here. –  Jun 02 '16 at 15:22
  • Actually, if that is the start of a "SQL Helper" class, you should just get rid of it. Most things query related are decidedly not reusable, like the DbCommand object. Other things like connections are intended to be created, used and disposed of as needed. Most everything which implements a `Dispose` method allocates some sort of resource under the hood. `Using` disposes of those things to free resources and prevent leaks in your app. [This poster](http://stackoverflow.com/q/31522891/1070452) ran out of resources because they were not disposing / `Using` – Ňɏssa Pøngjǣrdenlarp Jun 02 '16 at 15:27

0 Answers0