1

有人可以告诉我如何处理将字符串数组传递给我的 LINQ 存储过程吗?

storedProc 是通过将现有存储过程拖到 dbml 页面上来创建的。storedProc 接受我确定 in 值的 3 个(或任意数量)参数GetStringParams()

错误:No overload for storedProc takes 1 argument

DataClassDataContext db = new DataClassDataContext();
//storedProc takes 3 params
gridview.DataSource = db.storedProc(GetStringParams());
gridview.DataBind();

private string[] GetStringParams()
{
    string[] params = new string[3];    
    //Perform some logic here to determine which params to pass
    if (somethingIsTrue)
        params = new string[] { "param1", "param2", "param3" };
    else if (somethingElseIsTrue)
        params = new string[] { "param1", "param2", "" };
    else
        params = new string[] { "", "", "" };
    return params;
}

提前致谢。我搜索了这个问题,但找不到我正在寻找的确切内容。最好不必修改存储过程。

4

1 回答 1

1
DataClassDataContext db = new DataClassDataContext();
//storedProc takes 3 params
string[] param = GetStringParams();
gridview.DataSource = db.storedProc(param[0], param[1], param[2]);
gridview.DataBind();

private string[] GetStringParams()
{
    //Perform some logic here to determine which params to pass
    if (somethingIsTrue)
        return new string[] { "param1", "param2", "param3" };
    else if (somethingElseIsTrue)
        return new string[] { "param1", "param2", "" };
    else
        return new string[] { "", "", "" };
}

除非方法要求提供 params 数组,否则您不能将数组传递给多参数方法。

于 2012-05-01T16:26:29.127 回答