Jump to content
Xtreme .Net Talk

Problem from .NET 1.1 to 2.0... (Overload resolution failed...)


Recommended Posts

Posted

This code work fine in 1.1 but not 2.0. Any help? Thank you.

 

Dim Con As Object
       Dim sDB As String = "SQL"

       If sDB = "SQL" Then
           Con = New System.Data.SqlClient.SqlConnection
       Else
           Con = New System.Data.OleDb.OleDbConnection
       End If
       Con.Open("xxx")

 

I get this error:

System.MissingMemberException was unhandled by user code

Message="Overload resolution failed because no accessible 'Open' accepts this number of arguments."

Source="Microsoft.VisualBasic"

StackTrace:

at Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ResolveCall(Container BaseReference, String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)

at _Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\bpchia\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.vb:line 16

at System.Web.UI.Control.OnLoad(EventArgs e)

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

  • Administrators
Posted
If you have a variable called 'Con' and the two options you present both assign a database connection to it (which means they implement IDbConnection) why would 1) I assume it was meant to hold anything other than a database connection or 2) you want to store anything other than a database connection in it?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

Define a common interface that both classes implement and declare your variable as that interface.

 

Interface IExample
   Sub ExampleSub()
   Function ExampleFunction(ByVal exampleParameter As String) as String
End Interface

Class ExampleOne
   Implements IExample

   Public Function ExampleFunction(ByVal exampleParameter As String) As string Implements IExample.ExampleFunction
return string.Empty
   End Function

   Public Sub ExampleSub() Implements IExample.ExampleSub

   End Sub
End Class

Class ExampleTwo
   Implements IExample

   Public Function ExampleFunction(ByVal exampleParameter As String) As string Implements IExample.ExampleFunction
       Return String.Empty
   End Function

   Public Sub ExampleSub() Implements IExample.ExampleSub

   End Sub
End Class

 

You can then use this like

       Dim ex As IExample

       If True Then
           ex = New ExampleOne
       Else
           ex = New ExampleTwo
       End If

       ex.ExampleSub()

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...