adding data to listview

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 20
Reputation: BlkR is an unknown quantity at this point 
Solved Threads: 0
BlkR BlkR is offline Offline
Newbie Poster

adding data to listview

 
0
  #1
Jul 27th, 2009
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?

  1. Private Function listview()
  2.  
  3. Dim lSingleItem As ListViewItem 'The variable will hold the ListItem information so that you can add values to the column you want to change
  4.  
  5.  
  6. lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim) 'Create a new line, and assign the ListItem into the variable so we can add sub items
  7. lSingleItem.SubItems.Add(txtItemName.Text.Trim) 'The first sub item for the first line
  8. lSingleItem.SubItems.Add(FormatCurrency(txtUnitPrice.Text.Trim)) 'The second sub item for the first line
  9. lSingleItem.SubItems.Add(txtQty.Text.Trim)
  10. lSingleItem.SubItems.Add(FormatCurrency(txtUnitTotal.Text.Trim))
  11.  
  12. ' total = total + Val(txtTotal.Text.Trim)
  13. 'lblSubTotal.Text = total
  14.  
  15. End Function
  16.  
  17.  
  18. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  19.  
  20. Try
  21.  
  22.  
  23. Dim strSQL As String
  24.  
  25. 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 & """)"
  26.  
  27.  
  28. dc.Open()
  29. MessageBox.Show(strSQL)
  30.  
  31.  
  32.  
  33. Dim cmd As New OleDbCommand(strSQL, dc)
  34.  
  35.  
  36. cmd.ExecuteNonQuery()
  37.  
  38.  
  39. Call listview()
  40.  
  41. Catch
  42. MessageBox.Show("Error occured when trying to save data!", "Sale", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  43. txtItemNo.Focus()
  44.  
  45. End Try
  46.  
  47.  
  48. 'dc.Close()
  49. txtItemNo.Clear()
  50. txtItemName.Clear()
  51. txtQty.Clear()
  52. txtUnitPrice.Clear()
  53. txtUnitTotal.Clear()
  54.  
  55.  
  56. End Sub
Last edited by BlkR; Jul 27th, 2009 at 4:17 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: adding data to listview

 
0
  #2
Jul 27th, 2009
wht is the error tht u r getting?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: adding data to listview

 
0
  #3
Jul 27th, 2009
u can use data table along with command builder to add data.
but u will have to create a new row in the data table.
the inserting part will be taken care by the command builder
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: BlkR is an unknown quantity at this point 
Solved Threads: 0
BlkR BlkR is offline Offline
Newbie Poster

Re: adding data to listview

 
0
  #4
Jul 27th, 2009
the 2nd time i press the add button it goes straight to the error message that i put ie : "Error occured when trying to save data!"
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: adding data to listview

 
0
  #5
Jul 27th, 2009
why have u commented
dc.close.
the error might be because the connection is already open and u r again trying to open it
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: BlkR is an unknown quantity at this point 
Solved Threads: 0
BlkR BlkR is offline Offline
Newbie Poster

Re: adding data to listview

 
0
  #6
Jul 27th, 2009
oh i have changed that back before i posted it up here... still the same
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 465
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: adding data to listview

 
0
  #7
Jul 27th, 2009
Single quote needed.
  1. 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 & "')"
Last edited by adatapost; Jul 27th, 2009 at 8:57 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: BlkR is an unknown quantity at this point 
Solved Threads: 0
BlkR BlkR is offline Offline
Newbie Poster

Re: adding data to listview

 
0
  #8
Jul 27th, 2009
already tried that too still same
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: BlkR is an unknown quantity at this point 
Solved Threads: 0
BlkR BlkR is offline Offline
Newbie Poster

Re: adding data to listview

 
0
  #9
Jul 27th, 2009
already tried that but still the same .... and i think its only '" & textbox.text & "' rather than "'" ?... i dont think its the sql statement as the first time i add it, it works
Last edited by BlkR; Jul 27th, 2009 at 9:08 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 465
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: adding data to listview

 
0
  #10
Jul 27th, 2009
Do not use single quote with numeric fields. Non-numeric & date items must be surrounded with single quotes.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC