hi all,
i am doing payment form using datagridview in vb.net2008
when item add to item list
it will automatic display on my datagrid.
the problem now is,
the datagrid will display out my data when i press ADD Button twice .
here is my code..
am i make a mistake ?? plss help...
the module1.connect is use to connect to my Access database
Add Button
Private Sub uiAddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiAddButton.Click
Dim StockIdsearch As String = "select Stock_ID,Selling_Price from Stock WHERE Stock_Name = '" & Me.uiItemtxt.Text & "'"
Dim Adapter As New OleDbDataAdapter(StockIdsearch, Module1.connect)
Dim dt As New DataTable("Stock")
Adapter.Fill(dt)
Dim stockid As String = dt.Rows(0).Item(0)
Dim price As Double = dt.Rows(0).Item(1)
Dim caltotal As Double = Val(price) * Val(Me.uiQuantitytxtbox.Text)
Format(caltotal, "#####.##")
Dim count_total As String = "SELECT max(Item_No) FROM Invoice WHERE Invoice_ID='" & Me.uiInvoiceNotxt.Text & "'"
Dim countAD As New OleDbDataAdapter(count_total, Module1.connect)
Dim countdt As New DataTable("count")
countAD.Fill(countdt)
Dim count As Integer
If countdt.Rows(0).Item(0) Is DBNull.Value Then
count = 1
Dim insertinvoice As String = "INSERT INTO invoice(invoice_id,item_no,invoice_date,plate_no,contact_number,stock_id,Amount,price) VALUES('" & Me.uiInvoiceNotxt.Text & "'," & count & ",'" & Me.uiDatetxt.Text & "','" & Me.uiPlateNotxt.Text & "'," & Me.uicontactnotxtbox.Text & ",'" & stockid & "'," & Me.uiQuantitytxtbox.Text & ",'" & caltotal & "')"
Dim insertinvoicecom As New OleDbCommand(insertinvoice, Module1.connect)
insertinvoicecom.ExecuteNonQuery()
Else
count = countdt.Rows(0).Item(0) + 1
Dim Iupdatecheck As String = "SELECT stock_ID,Amount,Price FROM Invoice WHERE Invoice_ID='" & Me.uiInvoiceNotxt.Text & "' AND stock_ID='" & stockid & "'"
Dim IupdatecheckAD As New OleDbDataAdapter(Iupdatecheck, Module1.connect)
Dim Iupdatecheckdt As New DataTable("Checking")
IupdatecheckAD.Fill(Iupdatecheckdt)
If Iupdatecheckdt.Rows.Count = 0 Then
Dim insertinvoice As String = "INSERT INTO invoice(invoice_id,item_no,invoice_date,plate_no,contact_number,stock_id,Amount,price) VALUES('" & Me.uiInvoiceNotxt.Text & "'," & count & ",'" & Me.uiDatetxt.Text & "','" & Me.uiPlateNotxt.Text & "'," & Me.uicontactnotxtbox.Text & ",'" & stockid & "'," & Me.uiQuantitytxtbox.Text & ",'" & caltotal & "')"
Dim insertinvoicecom As New OleDbCommand(insertinvoice, Module1.connect)
insertinvoicecom.ExecuteNonQuery()
Else
Dim amount As Integer
Dim newtotal As Integer
amount = Iupdatecheckdt.Rows(0).Item(1) + Me.uiQuantitytxtbox.Text
newtotal = amount * Val(price)
Dim updateinvoice As String = "UPDATE invoice SET Amount=" & amount & ",price='" & newtotal & "' WHERE Invoice_ID='" & Me.uiInvoiceNotxt.Text & "' AND Stock_ID = '" & stockid & "'"
Dim updateinvoicecom As New OleDbCommand(updateinvoice, Module1.connect)
updateinvoicecom.ExecuteNonQuery()
End If
End If
Module1.close()
invoice()
End Sub
Invoice()
Public Sub invoice()
Try
Dim invoicedetail As String = "SELECT invoice.Item_No, invoice.Amount,invoice.Price,stock.Stock_Name FROM stock LEFT JOIN invoice ON stock.stock_ID = invoice.stock_ID WHERE Invoice_ID ='" & Me.uiInvoiceNotxt.Text & "'"
Dim invoicedetailDA As New OleDbDataAdapter(invoicedetail, Module1.connect)
Dim itemlist As New DataTable("invoice")
invoicedetailDA.Fill(itemlist)
uiitemlistdatagrid.DataSource = itemlist
uiStockDetailDataGrid.Refresh()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub