2016-04-23 9 views
0

私は価格を持つテーブルを持っていて、テキストボックスに3または3.00を入力したときにそう、それはすべてのレコードが表示されます、私は何かを作りたいので、指定された値を超えるデータを表示するにはどうすればよいですか?

| ID | Price | 
|----|-------| 
| 1 | 5.00 | 
| 50 | 6.70 | 

支払ったすべての価格「顧客」が持っている中それはその値を超えているので、IDが支払われた5ポンドは、ID 50と表示されます。私はそれらを私のdatagridviewに表示します。

何私がこれまで持っていることは次のとおりです。

myDA = New OleDbDataAdapter 
    myDataSet = New DataSet 
    myDA.SelectCommand = New OleDbCommand() 

    Try 
     cmd = New OleDbCommand() 
     cmd.CommandText = "Select sum(Paid) as total from tblorder" 
     cmd.Connection = con 
     If con.State = ConnectionState.Closed Then con.Open() 
     myDA.SelectCommand = cmd 
     myDA.Fill(myDataSet, "TTotal") 
     TextBox1.Text = CStr(myDataSet.Tables("TTotal").Rows(0).Item(0)) 
     DataGridView1.DataSource = myDataSet.Tables("TTotal").DefaultView 
     con.Close() 

    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    End Try 
+1

はそれらの '価格> X 'を表示するのRowFilterプロパティを使用します。データソースに応じて、CustomerIDフィルタが必要な場合もあります。 – Plutonix

答えて

0

次のように私はあなたのコードを変更している:

myDA = New OleDbDataAdapter 
myDataSet = New DataSet 

Dim price As Double = Convert.ToDouble(TextBox1.Text) 
'Save the value entered in textbox on the variable price 

Try 
    cmd = New OleDbCommand() 
    cmd.CommandText = "Select ID,Price from tableName where Price > @Price " 
    'tableName should be replaced with the name of your table 
    cmd.Parameters.AddWithValue("@Price", price) 
    'Add parameter to pass the price to the query 
    cmd.Connection = con 
    If con.State = ConnectionState.Closed Then con.Open() 
    myDA.SelectCommand = cmd 
    myDA.Fill(myDataSet, "tableName") 
    DataGridView1.DataSource = myDataSet.Tables("tableName").DefaultView 
    con.Close() 
Catch ex As Exception 
    MessageBox.Show(ex.Message) 
End Try 
+0

パーフェクト! ありがとうございました!:) –

関連する問題