Hi,
Currently having troubles in adding data to the listview i have created. It actually will add the first set of data to both the database and listview, but when i try to add a second lot of data it displays the error message that I have setup. Also how would I go about updating the same item with different amount of quantity but not adding a new set of row to it ? using the UPDATE method?
Private Function listview()
Dim lSingleItem As ListViewItem 'The variable will hold the ListItem information so that you can add values to the column you want to change
lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim) 'Create a new line, and assign the ListItem into the variable so we can add sub items
lSingleItem.SubItems.Add(txtItemName.Text.Trim) 'The first sub item for the first line
lSingleItem.SubItems.Add(FormatCurrency(txtUnitPrice.Text.Trim)) 'The second sub item for the first line
lSingleItem.SubItems.Add(txtQty.Text.Trim)
lSingleItem.SubItems.Add(FormatCurrency(txtUnitTotal.Text.Trim))
' total = total + Val(txtTotal.Text.Trim)
'lblSubTotal.Text = total
End Function
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
Dim strSQL As String
strSQL = "INSERT INTO trans2 (trans_ID, Item_ID, ItemName, Price, Qty, Total)VALUES (""" & txttran.Text & """ , """ & txtItemNo.Text & """ , """ & txtItemName.Text & """ , """ & txtUnitPrice.Text & """, """ & txtQty.Text & """ , """ & txtUnitTotal.Text & """)"
dc.Open()
MessageBox.Show(strSQL)
Dim cmd As New OleDbCommand(strSQL, dc)
cmd.ExecuteNonQuery()
Call listview()
Catch
MessageBox.Show("Error occured when trying to save data!", "Sale", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtItemNo.Focus()
End Try
'dc.Close()
txtItemNo.Clear()
txtItemName.Clear()
txtQty.Clear()
txtUnitPrice.Clear()
txtUnitTotal.Clear()
End Sub