insert multiple listbox items into the database in vb

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 7366 Views - Last Post: 15 October 2012 - 05:57 AM Rate Topic: -----

#16 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: insert multiple listbox items into the database in vb

Posted 11 October 2012 - 07:13 AM

Quote

but now am asking if its posible to have something like:

Why? You seem to be confused here on what you're actually trying to do. It might be a good time to understand how a database holds information and how you manage that information.


You have a column called Accessories in a Table called [Unit Order] The column contains rows (each item takes up a row)

Are you wanting more columns in your table to hold other information pertaining to each entry?

If you open your database table and look at the data, it will appear much like a listbox with a header of the column name.

First loop grabs Basin Level Platform

INSERT STATEMENT adds a new row putting Basin Level Platform in the Accessories column

Secon loop grabs Electronic Water Level Control Package

INSERT Statement adds a new row putting Electronic Water Level Control Package in the Accessories column.

At this point you have a datatable that contains one column with 2 rows.

Since you are only adding information into the single field (Accessories) you only need a single value.

How about trying the EXACT code you've been supplied in place of what you have in your For...Next loop and see what that gets you.

This post has been edited by CharlieMay: 11 October 2012 - 07:15 AM

Was This Post Helpful? 0
  • +
  • -

#17 christian Mukeba  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: insert multiple listbox items into the database in vb

Posted 11 October 2012 - 11:17 PM

i guess you understand very well....all i wanna know is?
Question: Is it possible to have more than one item insert into one column Row something like this image
Attached Image
Was This Post Helpful? 0
  • +
  • -

#18 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: insert multiple listbox items into the database in vb

Posted 12 October 2012 - 05:55 AM

Yes it's possible, but that kind of defeats the purpose of having a normalized database.

To do what you are asking should be done with 2 tables linked by a primary key from your main table to a foreign key in your accessories table

In this concept you might have something like

Table1 (Students)
StudentID PRIMARY KEY
StudentName
StudentSurname
School

Table2 (Accessories)
AccessoryID PRIMARY KEY
StudentID FOREIGN KEY (related to table on by a 1 to many relationship)
Accessory

So you data would look something like this:
Students Table
StudentID        StudentName    StudentSurname     School
12345            Charles        May                Harvard
99999           Chris          Mukeba             Unknown


Accessories table
AccessoryID      StudentID      Accessory
1                12345          Pen
2                12345          Book
3                12345          Pencil
4                12345          Bag
5                12345          Box
6                12345          Cup
7                12345          Plate
8                99999          Book
9                99999          Pencil


By joining these two tables you have a relationship based on the studentid where you can find that Charles May has 6 items and Chris Mukeba has 2

This way, you can perform a simple "Select Accessory FROM Accessories WHERE StudentID = 12345" and retrieve all the items that Charles May has.
Was This Post Helpful? 0
  • +
  • -

#19 christian Mukeba  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: insert multiple listbox items into the database in vb

Posted 14 October 2012 - 10:50 PM

Thank you charlie am gonna try what you suggest then i will let you know thanks again!!!!!
Was This Post Helpful? 0
  • +
  • -

#20 christian Mukeba  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: insert multiple listbox items into the database in vb

Posted 15 October 2012 - 05:57 AM

Thank you charlie your idea was magnificienti had to create another table for my accessories thanks again!!!!and in my GUI instead of using 2 listboxes that pass items to each other i remove one listbox and replace it by a datagridview....
your are genius man!!!!!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2