Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Transfer of data from listbox (vb express 2008) to table in msAccess

Transfer of data from listbox (vb express 2008) to table in msAccess

Scheduled Pinned Locked Moved Visual Basic
database
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sazd1
    wrote on last edited by
    #1

    I want to transfer the data displayed in listbox to a table and assign an IdNumber to each data transfer. And then to retrieve that data from that table for the relevant Id and after more additions to that data in list box, transfer again to table and save it permanently. I am using MsAccess as database. i have following data in list box in vb express 2008: Description Quantity Price Amount Order1 2 3 6 Order2 3 4 12 Order3 2 3 6 Order4 4 2 8 Total 32 So how i can transfer this data to a table giving it one Id and then retrieve that data in listbox from that table using the same id and after addition of more two Orders( Order5 and Order6) in the list box, transfer it back to that table for permanent save. Kindly advise me the code for this requirement.

    H 1 Reply Last reply
    0
    • S sazd1

      I want to transfer the data displayed in listbox to a table and assign an IdNumber to each data transfer. And then to retrieve that data from that table for the relevant Id and after more additions to that data in list box, transfer again to table and save it permanently. I am using MsAccess as database. i have following data in list box in vb express 2008: Description Quantity Price Amount Order1 2 3 6 Order2 3 4 12 Order3 2 3 6 Order4 4 2 8 Total 32 So how i can transfer this data to a table giving it one Id and then retrieve that data in listbox from that table using the same id and after addition of more two Orders( Order5 and Order6) in the list box, transfer it back to that table for permanent save. Kindly advise me the code for this requirement.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Do you know how to either insert or update a record in Access, from Visual Basic? If you did know, the solution should be obvious. Now this is such a common requirement that lots and lots of people have done it before. Lots of those have written about how to do it, including some people at Microsoft. So why not start out by Googling for Insert Access Record VB, or something similar. When you have tried, if you get stuck, ask again with some sample code and fully describe the error you are getting.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      S 1 Reply Last reply
      0
      • H Henry Minute

        Do you know how to either insert or update a record in Access, from Visual Basic? If you did know, the solution should be obvious. Now this is such a common requirement that lots and lots of people have done it before. Lots of those have written about how to do it, including some people at Microsoft. So why not start out by Googling for Insert Access Record VB, or something similar. When you have tried, if you get stuck, ask again with some sample code and fully describe the error you are getting.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        S Offline
        S Offline
        sazd1
        wrote on last edited by
        #3

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim total As Integer total = txtQuantity.Text * txtPrice.Text txtAmount.Text = total If ListBox1.Items.Count <> 0 Then ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1) End If ListBox1.Items.Add(txtId.Text + vbTab + txtDescription.Text + vbTab + txtQuantity.Text + vbTab + txtPrice.Text + vbTab + txtAmount.Text) total = total + Integer.Parse(txtAmount.Text) ListBox1.Items.Add("Total " + vbTab + vbTab + vbTab + total.ToString()) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("Id " + vbTab + "Description " + vbTab + "Quantity " + vbTab + "Price " + vbTab + "Amount ") End Sub Private Sub btnTransData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransData.Click Dim desc, qnty, price, amount As String Dim Cmd As OleDb.OleDbCommand Dim SQL As String Dim objCmd As New OleDb.OleDbCommand Dim Con = New OleDb.OleDbConnection ""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Propriet rio\Desktop\bd2.mdb") Dim id As Integer = 0 Con.Open() For Each item As String In ListBox1.Items If id <> 0 Then Dim parts() As String = item.Split(" ") SQL = "INSERT INTO TestTable (*) VALUES ('" & id.ToString & "', '" & parts(0) & "', " & parts(1) & ", '" & parts(2) & "', '" & parts(3) & "')" Cmd = New OleDb.OleDbCommand(SQL, Con) objCmd = New OleDb.OleDbCommand(SQL, Con) objCmd.ExecuteNonQuery() End If id = id + 1 Next Con.Close() End Sub it is giving the error ""IndexOutOfRangeExecption was unhandled"" kindly advise the correction.

        C D 2 Replies Last reply
        0
        • S sazd1

          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim total As Integer total = txtQuantity.Text * txtPrice.Text txtAmount.Text = total If ListBox1.Items.Count <> 0 Then ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1) End If ListBox1.Items.Add(txtId.Text + vbTab + txtDescription.Text + vbTab + txtQuantity.Text + vbTab + txtPrice.Text + vbTab + txtAmount.Text) total = total + Integer.Parse(txtAmount.Text) ListBox1.Items.Add("Total " + vbTab + vbTab + vbTab + total.ToString()) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("Id " + vbTab + "Description " + vbTab + "Quantity " + vbTab + "Price " + vbTab + "Amount ") End Sub Private Sub btnTransData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransData.Click Dim desc, qnty, price, amount As String Dim Cmd As OleDb.OleDbCommand Dim SQL As String Dim objCmd As New OleDb.OleDbCommand Dim Con = New OleDb.OleDbConnection ""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Propriet rio\Desktop\bd2.mdb") Dim id As Integer = 0 Con.Open() For Each item As String In ListBox1.Items If id <> 0 Then Dim parts() As String = item.Split(" ") SQL = "INSERT INTO TestTable (*) VALUES ('" & id.ToString & "', '" & parts(0) & "', " & parts(1) & ", '" & parts(2) & "', '" & parts(3) & "')" Cmd = New OleDb.OleDbCommand(SQL, Con) objCmd = New OleDb.OleDbCommand(SQL, Con) objCmd.ExecuteNonQuery() End If id = id + 1 Next Con.Close() End Sub it is giving the error ""IndexOutOfRangeExecption was unhandled"" kindly advise the correction.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Do you not know how to use a debugger ? I would try to help, but I'm not going to read all this code to try to work out what line is giving the error.

          Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

          1 Reply Last reply
          0
          • S sazd1

            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim total As Integer total = txtQuantity.Text * txtPrice.Text txtAmount.Text = total If ListBox1.Items.Count <> 0 Then ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1) End If ListBox1.Items.Add(txtId.Text + vbTab + txtDescription.Text + vbTab + txtQuantity.Text + vbTab + txtPrice.Text + vbTab + txtAmount.Text) total = total + Integer.Parse(txtAmount.Text) ListBox1.Items.Add("Total " + vbTab + vbTab + vbTab + total.ToString()) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("Id " + vbTab + "Description " + vbTab + "Quantity " + vbTab + "Price " + vbTab + "Amount ") End Sub Private Sub btnTransData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransData.Click Dim desc, qnty, price, amount As String Dim Cmd As OleDb.OleDbCommand Dim SQL As String Dim objCmd As New OleDb.OleDbCommand Dim Con = New OleDb.OleDbConnection ""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Propriet rio\Desktop\bd2.mdb") Dim id As Integer = 0 Con.Open() For Each item As String In ListBox1.Items If id <> 0 Then Dim parts() As String = item.Split(" ") SQL = "INSERT INTO TestTable (*) VALUES ('" & id.ToString & "', '" & parts(0) & "', " & parts(1) & ", '" & parts(2) & "', '" & parts(3) & "')" Cmd = New OleDb.OleDbCommand(SQL, Con) objCmd = New OleDb.OleDbCommand(SQL, Con) objCmd.ExecuteNonQuery() End If id = id + 1 Next Con.Close() End Sub it is giving the error ""IndexOutOfRangeExecption was unhandled"" kindly advise the correction.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            I thinky your SQL INSERT statement could use some work. First, I don't think it's a good idea to put that asterisk in there. Second, convert this so it uses a parameterized query instead of building an SQL statement using string concatenation.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups