i have a number of values in my database and i want to list only those values which is greater than zero

Recommended Answers

All 6 Replies

Hi

What have you tried so far?

Have you considered using an SQL Statement with a WHERE clause: SELECT * FROM YourTable WHERE YourColumn > 0?

HTH

no it is actually like this i have a table called pending in that i have a row called balance amount.i want to list from that table having balance amount greater than zero and i want to list it in datagrid view

any way thanks in advance

this is my code
Me.PendingTableAdapter.Fill(Me.GulfdataDataSet.pending)

    provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
    dataFile = "D:\gulf work\gulfdata.mdb" ' Change it to your Access Database location
    connString = provider & dataFile
    myConnection.ConnectionString = connString

    myConnection.Open()
    Dim str As String
    str = "SELECT * FROM pending WHERE balance > 0"
    Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
    dr = cmd.ExecuteReader
    While dr.Read()
        DataGridView1.DataSource = dr.Read()
    End While

Hi

Sorry, I did reply before you posted your code so I have removed that statement.

Looking at the code that you have posted you are using a DataReader to bind to the DataGridView. This is not correct. A DataReader is used as a means to read data in a forward only fashion, not as a collection of data. Instead, use a DataTable or DataSet (which is a collection of DataTables).

For example:

Using adapter As New OleDbDataAdapter(str, connString)

    Dim table As New DataTable
    adapter.Fill(table)

    'Bind the Table to the DataSource of the DataGridView
    DataGridView1.DataSource = table

End Using

HTH

commented: Great help. +15

thanks very much..now its working..hope u will help me in future..thankyou

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.