-1

Okay I'm trying to move from VB to C# with mixed success.

I'm getting the following errors:

  1. The best overloaded method match for '_DataInteraction.stdReturnDataTable(string, ref System.Collections.Generic.List, string)' has some invalid arguments

  2. Argument 2 must be passed with the 'ref' keyword

Both referencing: the myParamList noted with ** in

I have this code in C#

{

    List<SqlParameter> myParamList = new List<SqlParameter>();
    SqlParameter myParam = default(SqlParameter);

    myParam = new SqlParameter("@sAMAccountName", SqlDbType.VarChar);
    myParam.Value = ID;
    myParamList.Add(myParam);

    **dt = _DI.stdReturnDataTable("cit_ResolveUser", myParamList, "x");**

    return dt;
}

Now the code for stdReturnDataTable (just the top part which accepts the arguments)

public static DataSet stdReturnDataset(string procedureName, ref List<SqlParameter> myParameters, string db)
    {
       //code
    }

3 Answers 3

5

As the error message says, you should pass the argument with the ref keyword:

dt = DataInteraction.stdReturnDataTable("cit_ResolveUser", ref myParamList, "ParabisIntranet");

Also, as per your comment, it's a static method, you can not call it through an instance variable. Instead you need to qualify it using the typename.

But I suspect the ref keyword is actually not needed here, you can probably just remove it from the method signature.

public static DataSet stdReturnDataset(string procedureName, 
                                       List<SqlParameter> myParameters, 
                                       string db)
6
  • 1
    It's a static method, so you need to access it via the type name rather than an instance. what type is _DI? You need to do SomeClass.stdReturnDataset() where SomeClass is whatever type houses the stdReturnDataset method. Oct 11, 2012 at 7:50
  • 1
    So qualify it with the type name instead of an instance reference.
    – Rawling
    Oct 11, 2012 at 7:50
  • 1
    It's a static method, so you should call it using ClassName.MethodName syntax, exactly as the error message says. What's the name of the class containing the stdReturnDataset method?
    – jeroenh
    Oct 11, 2012 at 7:51
  • Thank you @DylanSmith _DI was just a new instance of DataInteraction class which housed the stdReturnDataset() function Oct 11, 2012 at 7:51
  • 1
    @Ryan Because the method is marked static, i.e. it doesn't "belong" to a specific instance but to the class itself.
    – Rawling
    Oct 11, 2012 at 7:58
1

You need to specify ref keyword with your method call.

dt = _DI.stdReturnDataTable("cit_ResolveUser", ref myParamList, "ParabisIntranet");
0
1

You need the ref keywoard:

dt = _DI.stdReturnDataTable("cit_ResolveUser", ref myParamList, "ParabisIntranet");

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.