Question Create a dynamic user interface to accept 1 or more line items to add to database?

Joined
Oct 20, 2006
Messages
21
Programming Experience
Beginner
I'm trying to code a small application that basically manages non product PO's. In other words a front end to a access database that can create/edit/print/email...purchase orders. PO's essentially have some standard info on each such as a PO number, vendor name, date and so forth. They will also have 1 or more items purchased on each PO. So in its most basic form I would have two tables in a database 1 with the general PO information and another with the lines items and the PO number as a key to associate them to the general info. So if a user runs this program and they want to buy 5 items how do I create a front end in VB.NET 2010 express that will accommodate a different number of items each time? How would the update/add query look to the database to accommodate dynamic entries as well?
 

s1ckOh

Well-known member
Joined
Aug 1, 2011
Messages
68
Location
San Diego, Ca
Programming Experience
Beginner
sounds like a homework assignment...

ive done something similar and what i did was put the purchased items in a listview and to add it to the database i use a for each listviewitem in listview.items

it looks something like this...

VB.NET:
        Dim myListItem As New ListViewItem
        For Each myListItem In ListView1.Items
            Dim sql As String = "INSERT INTO Info (ID, LName, FName) " & _
                                 "VALUES (@ID, @LName, @FName)"
            Dim cmd As New OleDbCommand(sql, cn)

            With cmd.Parameters
                .Add("@ID", OleDbType.Integer, 10, "ID").Value = TextBox1.Text 'CustomerID
                .Add("@LName", OleDbType.VarChar, 20, "LName").Value = myListItem.SubItems(0)
                .Add("@FName", OleDbType.VarChar, 20, "FName").Value = myListItem.SubItems(1)
            End With
            cmd.ExecuteNonQuery()
        Next
 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,577
Location
Sydney, Australia
Programming Experience
10+
The obvious option is a DataGridView. It can be bound to a DataTable so you can just use a DataAdapter so save the lot in one go. Also, there's no code required to insert the data into the grid. The user just starts typing.
 
Joined
Oct 20, 2006
Messages
21
Programming Experience
Beginner
What I did was create a few text boxes that (when told to) will add a row of data to the datagridview. I defined several unbound columns and the data goes right in. The problem I have now is I want to use the same datagrid to display queries from the database. I wrote a simple select statement and the data come in alright but it doesn't use the columns I defined, it generates new ones. It basically replicated/doubled the ones I made. Is there a way to tell the dataset tom map to the unbound columns I created?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,577
Location
Sydney, Australia
Programming Experience
10+
There sure is. Each column in the grid has a property to tell it which column/property of the data source to bind to. If I remember correctly, it's called DataPropertyName.
 
Joined
Oct 20, 2006
Messages
21
Programming Experience
Beginner
This is how I ended up getting it to work

Dim ds As New DataSet
Dim o As Object

o = ds.Tables.Item("mytable").Rows.Item(0).Item("PONumber")
txtPONumber.Text = o
 
Top Bottom