无法在自动完成方法中将类型 string 隐式转换为 string[]

发布于 2024-09-14 09:33:20 字数 1612 浏览 5 评论 0原文

下午好——今天是 13 号星期五,所以我当然有一个绝对的母马!!!

下面的代码“应该”创建一个将在文本框自动完成中使用的项目列表。

public string[] GetAutoComplete(string prefixText, int count)
    {
        try
        {
            string memberid = HttpContext.Current.Session["VDS_MemberID"].ToString(); 
            string locationid = HttpContext.Current.Session["VDS_LocationID"].ToString();
            string inhouse = HttpContext.Current.Session["VDS_Inhouse"].ToString();
            string supplier = HttpContext.Current.Session["VDS_Supplier"].ToString();
            string groupw = HttpContext.Current.Session["VDS_Group"].ToString();
            string external = HttpContext.Current.Session["VDS_External"].ToString();

            VDSORDAL.PDC_VDSOREntities autocomplete = new VDSORDAL.PDC_VDSOREntities();

            var r = (from p in  autocomplete.tblAutoCompletes
                    where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
                    select p);

            if (inhouse != "DoNotDisplayInhouse")
                         r = r.Where(p => p.ACItem == inhouse);

            if (supplier != "DoNotDisplaySupplier")
                r = r.Where(p => p.ACItem == supplier);

            if (groupw != "DoNotDisplayGroup")
                r = r.Where(p => p.ACItem == groupw);

            if (external != "DoNotDisplayExternal")
                r = r.Where(p => p.ACItem == external);

            return r.Distinct().OrderBy(p => p.ACItem).ToString();

        }

但是,我收到的问题标题是错误的。

谁能建议解决这个问题的方法吗?抱歉..我今天过得很糟糕。

Afternoon all - it's Friday th 13th so of course I am having an absolute mare!!!

The code below, 'should' create a list of items that will be used in a textbox autocomplete.

public string[] GetAutoComplete(string prefixText, int count)
    {
        try
        {
            string memberid = HttpContext.Current.Session["VDS_MemberID"].ToString(); 
            string locationid = HttpContext.Current.Session["VDS_LocationID"].ToString();
            string inhouse = HttpContext.Current.Session["VDS_Inhouse"].ToString();
            string supplier = HttpContext.Current.Session["VDS_Supplier"].ToString();
            string groupw = HttpContext.Current.Session["VDS_Group"].ToString();
            string external = HttpContext.Current.Session["VDS_External"].ToString();

            VDSORDAL.PDC_VDSOREntities autocomplete = new VDSORDAL.PDC_VDSOREntities();

            var r = (from p in  autocomplete.tblAutoCompletes
                    where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
                    select p);

            if (inhouse != "DoNotDisplayInhouse")
                         r = r.Where(p => p.ACItem == inhouse);

            if (supplier != "DoNotDisplaySupplier")
                r = r.Where(p => p.ACItem == supplier);

            if (groupw != "DoNotDisplayGroup")
                r = r.Where(p => p.ACItem == groupw);

            if (external != "DoNotDisplayExternal")
                r = r.Where(p => p.ACItem == external);

            return r.Distinct().OrderBy(p => p.ACItem).ToString();

        }

However, I am getting the question title as an error.

Can anyone suggest a way around this? Apologies..I am having a bad day.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷夜 2024-09-21 09:33:20

可能

return r.Distinct().OrderBy(p => p.ACItem).ToString();

应该是

return r.Distinct().OrderBy(p => p.ACItem).ToArray(); 

更新:

听起来这才是你真正的问题。尝试(以下代码是大脑编译的)

return (from p in r orderby p.ACItem desc select p.ACItem).ToArray();

我假设 ACItem 是您要返回的字符串,如果不是,请在数组中选择您想要的字符串。

或者可能

return (from p in r where p != null orderby p.ACItem desc select p.ACItem).ToArray();

需要 where p != null ,您非常需要检查 r 并查看其中的内容,但没有足够的信息来最终回答这个问题。
也就是说, .ToArray 而不是 .ToString 仍然是您问题的答案,其他任何问题都是不同的问题。

Possibly

return r.Distinct().OrderBy(p => p.ACItem).ToString();

should be

return r.Distinct().OrderBy(p => p.ACItem).ToArray(); 

Update:

Sounds like that's your real problem. Try (following code is brain-compiled)

return (from p in r orderby p.ACItem desc select p.ACItem).ToArray();

I'm assuming ACItem is the string you want to return, if not, select what you want in the array.

Or possibly

return (from p in r where p != null orderby p.ACItem desc select p.ACItem).ToArray();

the where p != null may be necessary, you pretty much need to inspect r and see what's in there, not really enough info to be able to answer this conclusively.
That said, .ToArray instead of .ToString is still the answer to your problem, anything else is a different question.

孤单情人 2024-09-21 09:33:20

最后一行应该是:

return r.Distinct().OrderBy(p => p.ACItem).ToArray();

The last line should be:

return r.Distinct().OrderBy(p => p.ACItem).ToArray();
累赘 2024-09-21 09:33:20

不要执行 ToString()。使用 ToArray()ConvertAll().ToArray()

Don't do a ToString(). Use either ToArray() or ConvertAll<string>().ToArray()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文