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

Re: vb.net 80 80


What have you tried so far?

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


Re: vb.net 80 80

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

Re: vb.net 80 80

any way thanks in advance

Re: vb.net 80 80

this is my code

    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

    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
Re: vb.net 80 80


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

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

End Using


commented: Great help. +15
Re: vb.net 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.