No accessible overloaded 'SqlDataAdapter.SelectCommand' error message....plz respond

sundeep_ns

New member
Joined
Jun 20, 2008
Messages
1
Programming Experience
Beginner
I am new to ASP.net . I am trying to open a web page which is giving the following error message: Plz review and give a possible reason behind the error. If you want to have a look at the code just let me know:



No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.AmbiguousMatchException: No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[AmbiguousMatchException: No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)]
Microsoft.VisualBasic.CompilerServices.VBBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo culture, String[] names, Object& ObjState) +6971
Microsoft.VisualBasic.CompilerServices.VBBinder.InvokeMember(String name, BindingFlags invokeAttr, Type objType, IReflect objIReflect, Object target, Object[] args, String[] namedParameters) +576
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType) +1250
Microsoft.VisualBasic.CompilerServices.LateBinding.LateSet(Object o, Type objType, String name, Object[] args, String[] paramnames) +27
Req_Agent.Employee.FillDataset(String strConnect, String CmdText) in C:\LESA\Source_code\RC3\Req_Agent\Employee.vb:149
Req_Agent.Employee.LoginValid() in C:\LESA\Source_code\RC3\Req_Agent\Employee.vb:89
Req_Agent.LoginMain.btnLogin_Click(Object sender, EventArgs e) in C:\LESA\Source_code\RC3\Req_Agent\LoginMain.aspx.vb:134
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
 
Since you have posted no code we can only guess. But I think a fair guess would be that the argument you used is not of the type SqlCommand or DbCommand, just as the error message states. To correct this error, I would use a parameter that is of type SqlCommand or DbCommand, depending on which overload you want to use.
 
I'm getting the exact same error. I worked great for months. Can't figure out what happened? Nothing changed on the server. Did you ever figure it out?
 
I am getting this error message
No accessible overloaded 'SqlDataAdapter.SelectCommand'

No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.AmbiguousMatchException: No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)


Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[AmbiguousMatchException: No accessible overloaded 'SqlDataAdapter.SelectCommand' is most specific for these arguments:
Public Sub set_SelectCommand(value As System.Data.SqlClient.SqlCommand)
Public Sub set_SelectCommand(value As System.Data.Common.DbCommand)]
Microsoft.VisualBasic.CompilerServices.VBBinder.Bi ndToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo culture, String[] names, Object& ObjState) +6971
Microsoft.VisualBasic.CompilerServices.VBBinder.In vokeMember(String name, BindingFlags invokeAttr, Type objType, IReflect objIReflect, Object target, Object[] args, String[] namedParameters) +576
Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType) +1250
Microsoft.VisualBasic.CompilerServices.LateBinding .LateSet(Object o, Type objType, String name, Object[] args, String[] paramnames) +27
Req_Agent.Employee.FillDataset(String strConnect, String CmdText) in C:\LESA\Source_code\RC3\Req_Agent\Employee.vb:149
Req_Agent.Employee.LoginValid() in C:\LESA\Source_code\RC3\Req_Agent\Employee.vb:89
Req_Agent.LoginMain.btnLogin_Click(Object sender, EventArgs e) in C:\LESA\Source_code\RC3\Req_Agent\LoginMain.aspx.v b:134
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
_____________________________________________________________________________

This is my code:

Public myComm As New SqlCommand(strQry, myConn)
Public SelectCommand As New SqlClient.SqlCommand()
Public strconn As String
Public myConn As New SqlConnection(strConn)



Public Sub set_SelectCommand(ByVal value As System.Data.SqlClient.SqlCommand)
SelectCommand.CommandType = CommandType.StoredProcedure
SelectCommand.Connection = myConn
End Sub



Public Sub GetInfoNew(ByVal ParamNum As Integer, ByVal myStoredProcedure As String, ByVal Arrayvalues As Array, _
ByVal DAName As SqlDataAdapter, ByVal TableName As DataTable)
Dim par As String
Dim prod As String
Dim paramstring As String

myComm.CommandType = CommandType.StoredProcedure
myComm.CommandText = myStoredProcedure

For rowIndex = 0 To ParamNum - 1
par = Arrayvalues(rowIndex, 0)
prod = Arrayvalues(rowIndex, 1)
spParam = New SqlParameter(par, SqlDbType.VarChar)

myComm.Parameters.Add(spParam)
myComm.Parameters(par).Value = prod

Next

TableName.Clear()
Try
DAName.SelectCommand = myComm
Catch err1 As Exception
MessageBox.Show(err1.Message)
End Try

Try
DAName.Fill(TableName)
Catch err1 As Exception
MessageBox.Show(err1.Message)
End Try
rowCount = TableName.Rows.Count
rowIndex = 0
End Sub
 
First up, the stack trace shows that you're using late-binding. If you turn Option Strict On then I bet the compiler will show you where your error is and will refuse to even compile your code until you fix it, which is a good thing.

Second, the error message seems to be saying that you are calling set_SelectCommand incorrectly. You've shown us where the method is declared but not where you're calling it.
 
VB.NET has Option Strict Off by default. I understand why Microsoft have made this decision but I still think it's unfortunate. I would suggest that you turn Option Strict On for all your current projects and also turn it On by default in the IDE, so it will be On for all future projects.

To turn it On at the project level, visit the Compile tab of the project properties. To set it On by default in future project, select Tools -> Options from the main menu and select Projects and Solutions -> VB Defaults. You can then turn it Off at the file level if you ever need to use late binding, which you rarely, if ever, will.
 

Latest posts

Back
Top