on the screen In a grid view all the parts are displayed. I have a button. When I click it I have to generate a purchase order and send it to Excel. These are the steps I am doing.
1. select the parts on the gridview you want to send.
2.create a data table to move all the selected parts.
3.Generate a purchase order number.
4.Update the gridview with purchase order number if it is selected for the purchase order.
5.Send the contents of the created data table to excel.
Before I send data to Excel I need to update the gridview. I am able to send data to excel. But unable to update the gridview before I send data.
I hope I explained the properly. Please help!!
This is my code.
Protected Sub cmdGeneratePO_Click(sender As Object, e As EventArgs) Handles cmdGeneratePO.Click
Dim JobNo As String = ddlJob.SelectedItem.Value
Dim PONumber As String = Generate_PO_Number()
Dim dt As New DataTable()
dt = Make_DataTableFor_PO_RFQ()
If dt.Rows.Count = 0 Then
MessageBox("Please select the parts", lblMessage)
Dim totBOMCost As Double
lblTotalCost.Text = ""
If dt.Rows.Count > 0 Then
For Each row As DataRow In dt.Rows
Dim cost As Double = row("TotalCost")
totBOMCost = totBOMCost + cost
Dim Cust_Name As String = ddlCustomer.SelectedItem.Text
Dim Bom_Name As String = ddlBOM.SelectedItem.Text
''Update the PO number in the DB
'Fill the grid
Dim Sql As String = " SELECT Parts.partID, Parts.ManufacturerPartNo as ManuPartNo, Parts.LastOrderedCost,Parts.PartDescription as Description, " & _
" MANUFACTURER.ManuName as Manufacturer, bom.BomMstID, bom.QtyOrdered, bom.QtyReceived, bom.QtyRequired as Quantity,Parts.LastOrderedCost*bom.QtyRequired as Cost, bom.ExpectedDelDt, " & _
" bom.WearSparePartFlag,BOM.PONum FROM BOM, PARTS, Manufacturer where parts.PartID = bom.PartID and parts.ManuID = Manufacturer.ManuID and " & _
" BOM.CustomerID=" & ddlCustomer.SelectedItem.Value & " and JobNum = '" & ddlJob.SelectedItem.Value & "' and BomID = " & ddlBOM.SelectedItem.Value & " and RevisionLvl='" & ddlRevLvl.SelectedItem.Value & "' order by ManuPartNo"
Dim rowCount As Integer = Fill_SelectedParts_Grid(Sql)
Export_PO_ToExcel(dt, Cust_Name, Bom_Name, JobNo, totBOMCost, PONumber)
Catch ex As Exception
MessageBox("Error while generating PO :" & ex.Message, lblMessage)
"Fill_SelectedParts_Grid" should update the grid. Infact it is updating if I remove "Export_PO_ToExcel(dt, Cust_Name, Bom_Name, JobNo, totBOMCost, PONumber)" code.