0

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

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by bluehangook629
0
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)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.