I am learning to program and try ti build a store management windows form application with vb.net. The database is on a SQL Server 2008r2. For each delivery I want to have a control on a form, where I can select the accompanying papers.I tried with a bound listbox that takes the items from another table in the database. I can select multiple items but only the first from all selected gets in the table field in the SQL server after updating the dataset. I want all the selected items to be written in the database in the "accompanying papers" field of the "deliveries" table. Is it possible to do even if I have to use another control instead of listbox?
1 Replies - 408 Views - Last Post: 14 July 2012 - 09:43 AM
#1
multiple selection control filling all selected items in a table field
Posted 14 July 2012 - 05:47 AM
Replies To: multiple selection control filling all selected items in a table field
#2
Re: multiple selection control filling all selected items in a table field
Posted 14 July 2012 - 09:43 AM
For example: you have Table1 with 3 fields (F1,F2,F3).
F1 is displayed in listbox, F1 and F2 are shown in textbox1 and textbox2. You have 3 selected items in listbox and you want to make same changes in F2 for each selected item. You can do this:
You can make changes in dataset.Table1.F2 in each row with the same index from selected items..and then call TableAdapter.update.. you can get all selected indexes from Listbox.SelectedIndices.
OR if you know how to create sql query:
UPDATE F2 (set F2="new record") WHERE F1 = "item1" or F1 = "item2" or F1 = "item3". Then you can use SqlCommand.ExecuteNonQuery method and after that just refresh dataset.
F1 is displayed in listbox, F1 and F2 are shown in textbox1 and textbox2. You have 3 selected items in listbox and you want to make same changes in F2 for each selected item. You can do this:
You can make changes in dataset.Table1.F2 in each row with the same index from selected items..and then call TableAdapter.update.. you can get all selected indexes from Listbox.SelectedIndices.
OR if you know how to create sql query:
UPDATE F2 (set F2="new record") WHERE F1 = "item1" or F1 = "item2" or F1 = "item3". Then you can use SqlCommand.ExecuteNonQuery method and after that just refresh dataset.
This post has been edited by sela007: 14 July 2012 - 09:50 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|