clockwork3orange
Member
- Joined
- Oct 20, 2006
- Messages
- 21
- Programming Experience
- Beginner
I wrote a VB.NET 2010 application that writes to a MS Access DB via an ODBC connection. This application is intended to take the place of the paper based Non Product PO system. The functionality in question works as follows:
A user opens the program to a blank PO form. They can search for an existing PO or create a new one. They are required to fill in the header information (stored in a table) as well the line items (saved to a different table) creating a 1 to many relationship. In the case of a new PO, after adding all the required info they would hit the insert button to save all the new records. Hitting this button will check for empty fields before creating the ODBC connection. It then tracks if you did a successful search. If so it will not try to add the header info back into the database because it already exists so it knows the users is attempting to edit or add to an existing record. If the request is new it will loop through all the line items in the PO and execute the query then it proceeds to execute the header. The issues I have seen is a user enters bad data in the header and it fails executing. So what happens is the lines items exist but no headers. When they try to fix it they get an error that the unique Id is already used and I need to go in the DB to clean it up.
Any ideas how to fix all this? Also any clean way to have one button do all updates and inserts?
If SearchCount = False Then
For i = 0 To DataGridView1.RowCount - 2
cmd.CommandText = "INSERT INTO POItems (PONumber, ItemNumber, Quantity, PartNumber, Description, UnitPrice, Total, QuantityReceived, PackingSlip, AccountCodeLine, Asset)" + _
" VALUES (" + DataGridView1.Item("PONumber", i).Value + "," + DataGridView1.Item("ItemNumber", i).Value + _
", " + DataGridView1.Item("Quantity", i).Value + ", '" + DataGridView1.Item("PartNumber", i).Value + _
"', '" + DataGridView1.Item("Description", i).Value + "', " + DataGridView1.Item("UnitPrice", i).Value + _
", " + DataGridView1.Item("Total", i).Value + ", " + DataGridView1.Item("QuantityReceived", i).Value + _
", '" + DataGridView1.Item("PackingSlip", i).Value + "', " + DataGridView1.Item("AccountCode", i).Value + _
", '" + DataGridView1.Item("Asset", i).Value + "')"
cmd.ExecuteNonQuery()
Next
cmd.CommandText = "INSERT INTO POHeader (PONumber, PODate, ShipVIA, RDDate, FOB, VQDDate, Terms, Vendor, AccountCode, " + _
"Plant, Confirmation, Certification, Requestor, Approver, Route, Notes, Void, Open, AccApp, POType )" + _
"VALUES (" + txtPONumber.Text + ", #" + DTPDate.Text + "#, '" + cbShipVIA.Text + "', #" + DTPRDD.Text + "#, '" + _
cbFOB.Text + "', #" + DTPVQDD.Text + "#, '" + txtTerms.Text + "', '" + txtVendor.Text + "', '" + txtAccount.Text + "', '" + _
cbPlant.Text + "', " + cbConfirmation.Text + ", " + cbCertification.Text + ", '" + txtRequestor.Text + "', '" + _
txtApprover.Text + "', '" + txtRoute.Text + "', '" + rtbNotes.Text + "', " + cbVoid.Text + ", " + cbOpen.Text + ", '" + txtAcctApp.Text + "', '" + cbPOType.Text + "')"
cmd.ExecuteNonQuery()
ElseIf SearchCount = True Then
For i = rows To DataGridView1.RowCount - 2
cmd.CommandText = "INSERT INTO POItems (PONumber, ItemNumber, Quantity, PartNumber, Description, UnitPrice, Total, QuantityReceived, PackingSlip, AccountCodeLine, Asset)" + _
" VALUES (" + DataGridView1.Item("PONumber", i).Value + "," + DataGridView1.Item("ItemNumber", i).Value + _
", " + DataGridView1.Item("Quantity", i).Value + ", '" + DataGridView1.Item("PartNumber", i).Value + _
"', '" + DataGridView1.Item("Description", i).Value + "', " + DataGridView1.Item("UnitPrice", i).Value + _
", " + DataGridView1.Item("Total", i).Value + ", " + DataGridView1.Item("QuantityReceived", i).Value + _
", '" + DataGridView1.Item("PackingSlip", i).Value + "', " + DataGridView1.Item("AccountCode", i).Value + _
", '" + DataGridView1.Item("Asset", i).Value + "')"
cmd.ExecuteNonQuery()
Next
End If
A user opens the program to a blank PO form. They can search for an existing PO or create a new one. They are required to fill in the header information (stored in a table) as well the line items (saved to a different table) creating a 1 to many relationship. In the case of a new PO, after adding all the required info they would hit the insert button to save all the new records. Hitting this button will check for empty fields before creating the ODBC connection. It then tracks if you did a successful search. If so it will not try to add the header info back into the database because it already exists so it knows the users is attempting to edit or add to an existing record. If the request is new it will loop through all the line items in the PO and execute the query then it proceeds to execute the header. The issues I have seen is a user enters bad data in the header and it fails executing. So what happens is the lines items exist but no headers. When they try to fix it they get an error that the unique Id is already used and I need to go in the DB to clean it up.
Any ideas how to fix all this? Also any clean way to have one button do all updates and inserts?
If SearchCount = False Then
For i = 0 To DataGridView1.RowCount - 2
cmd.CommandText = "INSERT INTO POItems (PONumber, ItemNumber, Quantity, PartNumber, Description, UnitPrice, Total, QuantityReceived, PackingSlip, AccountCodeLine, Asset)" + _
" VALUES (" + DataGridView1.Item("PONumber", i).Value + "," + DataGridView1.Item("ItemNumber", i).Value + _
", " + DataGridView1.Item("Quantity", i).Value + ", '" + DataGridView1.Item("PartNumber", i).Value + _
"', '" + DataGridView1.Item("Description", i).Value + "', " + DataGridView1.Item("UnitPrice", i).Value + _
", " + DataGridView1.Item("Total", i).Value + ", " + DataGridView1.Item("QuantityReceived", i).Value + _
", '" + DataGridView1.Item("PackingSlip", i).Value + "', " + DataGridView1.Item("AccountCode", i).Value + _
", '" + DataGridView1.Item("Asset", i).Value + "')"
cmd.ExecuteNonQuery()
Next
cmd.CommandText = "INSERT INTO POHeader (PONumber, PODate, ShipVIA, RDDate, FOB, VQDDate, Terms, Vendor, AccountCode, " + _
"Plant, Confirmation, Certification, Requestor, Approver, Route, Notes, Void, Open, AccApp, POType )" + _
"VALUES (" + txtPONumber.Text + ", #" + DTPDate.Text + "#, '" + cbShipVIA.Text + "', #" + DTPRDD.Text + "#, '" + _
cbFOB.Text + "', #" + DTPVQDD.Text + "#, '" + txtTerms.Text + "', '" + txtVendor.Text + "', '" + txtAccount.Text + "', '" + _
cbPlant.Text + "', " + cbConfirmation.Text + ", " + cbCertification.Text + ", '" + txtRequestor.Text + "', '" + _
txtApprover.Text + "', '" + txtRoute.Text + "', '" + rtbNotes.Text + "', " + cbVoid.Text + ", " + cbOpen.Text + ", '" + txtAcctApp.Text + "', '" + cbPOType.Text + "')"
cmd.ExecuteNonQuery()
ElseIf SearchCount = True Then
For i = rows To DataGridView1.RowCount - 2
cmd.CommandText = "INSERT INTO POItems (PONumber, ItemNumber, Quantity, PartNumber, Description, UnitPrice, Total, QuantityReceived, PackingSlip, AccountCodeLine, Asset)" + _
" VALUES (" + DataGridView1.Item("PONumber", i).Value + "," + DataGridView1.Item("ItemNumber", i).Value + _
", " + DataGridView1.Item("Quantity", i).Value + ", '" + DataGridView1.Item("PartNumber", i).Value + _
"', '" + DataGridView1.Item("Description", i).Value + "', " + DataGridView1.Item("UnitPrice", i).Value + _
", " + DataGridView1.Item("Total", i).Value + ", " + DataGridView1.Item("QuantityReceived", i).Value + _
", '" + DataGridView1.Item("PackingSlip", i).Value + "', " + DataGridView1.Item("AccountCode", i).Value + _
", '" + DataGridView1.Item("Asset", i).Value + "')"
cmd.ExecuteNonQuery()
Next
End If