简体   繁体   中英

Error: Specified method is not supported?

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.

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.

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();

在此处输入图片说明

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.

Try using it in Startup.cs

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM