错误:不支持指定的方法?

发布于 2024-08-25 02:13:17 字数 940 浏览 4 评论 0原文

当我尝试调用 Find() 时,我不断收到此错误

public void findTxt(string text)
    {
        BindingSource src = new BindingSource();
        src.DataSource = dataGridView1.DataSource;
        src.Position = src.Find("p_Name", text);    // Specified method is not supported

        if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() == text)
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }
        else if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() != text)
        {
            MessageBox.Show("Item not found!!");
        }
        else
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }

    }

编辑:

从另一个表单调用 findText 方法时收到该错误,但是从主表单调用此方法不会导致此类错误。

I keep getting this error when I try to call Find()

public void findTxt(string text)
    {
        BindingSource src = new BindingSource();
        src.DataSource = dataGridView1.DataSource;
        src.Position = src.Find("p_Name", text);    // Specified method is not supported

        if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() == text)
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }
        else if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() != text)
        {
            MessageBox.Show("Item not found!!");
        }
        else
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }

    }

Edit:

I get that error when calling findText method from another form, However calling this method from the main form doesn't result in such an error.

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

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

发布评论

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

评论(3

允世 2024-09-01 02:13:17

它支持什么操作取决于底层数据源。我相信 DataTable 是唯一一个开箱即用支持这一点的。您可以通过以下方式检查(在本例中):

IBindingListView blv = yourDataSource as IBindingListView;
bool canSearch = blv != null && blv.SupportsSearching;

So;底层数据源是什么? List(甚至 BindingList)不会提供此功能。

It is up to the underlying data-source what operations it supports. I believe that DataTable is the only one that out of the box supports this. You could check (in this case) via:

IBindingListView blv = yourDataSource as IBindingListView;
bool canSearch = blv != null && blv.SupportsSearching;

So; what is the underlying data source? A List<T> (or even BindingList<T>) won't provide this.

白鸥掠海 2024-09-01 02:13:17

我的 Asp.Net Core API 中出现此错误。这是因为 Asp.Net Framework 和 .Net Core 中的 API 差异。我的应用程序位于 Asp.Net Framework 中,我已将其迁移到 .Net Core。下面的代码在编译时总是可以正常工作,但是在运行时失败并抛出错误 System.NotSupportedException: '不支持指定的方法。'

Request.Body.Seek(0, SeekOrigin.Begin);
var streamReader = new StreamReader(Request.Body);
bodyData = await streamReader.ReadToEndAsync();

在此处输入图像描述

要解决这个问题,您所要做的就是按照下面的正确方式进行更改。

bodyData = wait new StreamReader(Request.Body, Encoding.Default).ReadToEndAsync();

您还应该添加 System.Text 命名空间。

希望有帮助。

I had this error in my Asp.Net Core API. It was because of the the API difference in Asp.Net Framework and .Net Core. My application was in Asp.Net Framework and I had migrated it to the .Net Core. The below code will always work fine in the compile time, but this was failing at the run time and was throwing the error System.NotSupportedException: 'Specified method is not supported.'

Request.Body.Seek(0, SeekOrigin.Begin);
var streamReader = new StreamReader(Request.Body);
bodyData = await streamReader.ReadToEndAsync();

enter image description here

To fix this all you have to do is to change it in the right way as below.

bodyData = await new StreamReader(Request.Body, Encoding.Default).ReadToEndAsync();

You should also add System.Text namespace.

Hope it helps.

对岸观火 2024-09-01 02:13:17

尝试在 Startup.cs 中使用它

app.Use((context, next) =>{context.Request.EnableBuffering();return next();});

Try using it in Startup.cs

app.Use((context, next) =>{context.Request.EnableBuffering();return next();});

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