My Table in database
Now in this table I have departments like 1 & 2.
I want to print separate tokens for each department.
This is code for reading unique departments from table (if available)
Public Sub token_print_()
openconnection1()
Try
Dim searchQuery As String = "select distinct department as 'department' from tb_transactions where invoice_id='" & TextBox1.Text & "'"
Dim command As New SqlCommand(searchQuery, MYSQLCon)
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable
adapter.Fill(table)
For Each row As DataRow In table.Rows
For Each colu In table.Columns
receipt_filldatagridview2(row(colu))
Next
Next
command.Dispose()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Receipt Fill Error 107")
End Try
End Sub
What I want is to read each unique department (like 1 & 2) and then fill the datagridview
with this one by one and printing tokens. (by passing each department to receipt_filldatagridview2(row(colu))
)
But the problem is For each statement is not working as it should. (datagridview
only shows items with department 2 and skip the department 1 in each statement)
Here is code for datagridview
Public Sub receipt_filldatagridview2(ByVal dept As String)
openconnection1()
Try
DataGridView_thermal.AutoGenerateColumns = False
Dim searchQuery As String = "Select tb_transactions.product_name as 'product_name', cast(quantity as numeric(36,1)) as 'quantity', tb_transactions.rate as 'rate' from tb_transactions where tb_transactions.invoice_id = '" & TextBox1.Text & "' AND tb_transactions.department = '" & dept.ToString & "'"
Dim command As New SqlCommand(searchQuery, MYSQLCon)
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable
adapter.Fill(table)
DataGridView_thermal.DataSource = table
BTPRINT.PerformClick()
table.Dispose()
adapter.Dispose()
command.Dispose()
Catch ex As Exception
MsgBox(ex.Message, "Receipt Fill Error 107")
End Try
End Sub