使用Excel(oledb)和C#将文本框中input的数据显示到dataGridView中

我需要你的帮助。 我想根据我input的文本框中显示的所有数据。 在文本框中input的数字将是我的门槛。 我想显示表格“拒绝”中的所有数据超过我的阈值datagridview。 谁能帮我 ? 这是我的代码:

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]; } } 

谁能帮我 ? 我感到困惑,我只能显示超过我的门槛的数据。 谢谢

尝试这个:

 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; }