have been trying to display on my data grip view but is not.
i want a situation where by it will display on the datagrip view base on the invoice number, below are the code

Private Sub getLastID()
Dim oleDBDR As SqlDataReader
Dim oleDBCommand As New SqlCommand

With oleDBCommand
.Connection = con
.CommandText = "SELECT * FROM tblAddOrder ORDER BY InvoiceNo DESC"
End With
oleDBDR = oleDBCommand.ExecuteReader
If oleDBDR.Read Then
lblOrNumber.Text = Val(oleDBDR.Item(0)) + 1
oleDBDR.Close()
End If
End Sub

Private Sub loadDATA()
Dim oleDBC As New SqlCommand
Dim oleDBDR As SqlDataReader
Dim c As Integer
c = 0
With oleDBC
.Connection = con
.CommandText = "SELECT * FROM tblAddOrder Where InvoiceNo='" & lblOrNumber.Text & "'"
End With
oleDBDR = oleDBC.ExecuteReader

If oleDBDR.HasRows Then
While oleDBDR.Read
DataGridView1.Rows.Add()
DataGridView1.Item(0, c).Value = oleDBDR.Item(3)
DataGridView1.Item(1, c).Value = oleDBDR.Item(4)
DataGridView1.Item(2, c).Value = oleDBDR.Item(5)
DataGridView1.Item(3, c).Value = oleDBDR.Item(6)
DataGridView1.Item(4, c).Value = oleDBDR.Item(7)
c = c + 1
End While
oleDBDR.Close()
Else
End If
End Sub

Private Sub getLastID()
Dim oleDBDR As SqlDataReader
Dim oleDBCommand As New SqlCommand

With oleDBCommand
.Connection = con
.CommandText = "SELECT * FROM tblAddOrder ORDER BY InvoiceNo DESC"
End With
oleDBDR = oleDBCommand.ExecuteReader
If oleDBDR.Read Then
lblOrNumber.Text = Val(oleDBDR.Item(0)) + 1
oleDBDR.Close()
End If
End Sub

Private Sub loadDATA()
Dim oleDBC As New SqlCommand
Dim oleDBDR As SqlDataReader
Dim c As Integer
c = 0
With oleDBC
.Connection = con
.CommandText = "SELECT * FROM tblAddOrder Where InvoiceNo='" & lblOrNumber.Text & "'"
End With
oleDBDR = oleDBC.ExecuteReader

If oleDBDR.HasRows Then
While oleDBDR.Read
DataGridView1.Rows.Add()
DataGridView1.Item(0, c).Value = oleDBDR.Item(3)
DataGridView1.Item(1, c).Value = oleDBDR.Item(4)
DataGridView1.Item(2, c).Value = oleDBDR.Item(5)
DataGridView1.Item(3, c).Value = oleDBDR.Item(6)
DataGridView1.Item(4, c).Value = oleDBDR.Item(7)
c = c + 1
End While
oleDBDR.Close()
Else
End If
End Sub

Add this to sort your gridview

DataGridView1.Sort(DataGridView1.Columns("YourColumnIndex"), _
           System.ComponentModel.ListSortDirection.Descending)
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.