1

I need your help. I want to show all data based on number I input in textbox. Number that is inputted in textbox will be my threshold. I want to show all data in table "Reject" that more than my threshold to datagridview. Can anyone help me ? This is my code :

if (NominalBox.Text != "")
{
    int thresholdcas50;
    Int32.TryParse(NominalBox.Text, out thresholdcas50); 

    koneksi.Open();
    System.Data.DataTable aksesdatatabel;
    aksesdatatabel = koneksi.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    koneksi.Close();

    OleDbCommand command = new OleDbCommand
    (
        "select Reject from [Sheet1$]", koneksi
    );

    DataSet coba = new DataSet();
    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
    adapter.Fill(coba);

    // Here I want to read all datas in "Reject" and convert
    // them into integer. There is an error here.
    // It says "Input string was not in a correct format".
    int x = int.Parse(coba.Tables[0].ToString());

    if (x > thresholdcas50)
    {
        // I stuck here. I don't know how to show all datas that
        // more than my threshold.
        dataGridView1.DataSource = coba.Tables[0];
    }
}

Can anyone help me ? I confused how I can show only data that more than my threshold. Thank you

1 Answer 1

1

Try this:

if (NominalBox.Text != "")
{
    int thresholdcas50;
    Int32.TryParse(NominalBox.Text, out thresholdcas50);

    koneksi.Open();
    System.Data.DataTable aksesdatatabel;
    aksesdatatabel = koneksi.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    koneksi.Close();


    OleDbCommand command = new OleDbCommand
    (
        "select Reject from [Sheet1$]", koneksi
    );

    DataSet coba = new DataSet();
    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
    adapter.Fill(coba);

    // Just made a variable to quick identify your table.
    var table = coba.Tables[0];

    // Make a view from your table.
    var view = new DataView(table);

    // Make a filter on the view.
    view.RowFilter = string.Format("Reject > {0}", thresholdcas50);

    // Now set the DataSource to your filter.
    dataGridView1.DataSource = view;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hai Ismael. Thanks for answering. I had tried your code and I found an error on view.RowFilter = string.Format("Reject > {0}", thresholdcas50); It says "Cannot perform '>' operation on System.String and System.Int32" Can you hep me ?
Ahh ! I have edited your code and it works ! I added '' signs to your code. So, it be view.RowFilter = string.Format("Reject > '{0}'", thresholdcas50); Btw, thanks so much Ismael :)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.