I am using VB6.
I have bound my DataList1 to the Adodc1 data control.
Is it possible to add data from DataList1 to DataList2 ?
If so what code would I use ?
Printable View
I am using VB6.
I have bound my DataList1 to the Adodc1 data control.
Is it possible to add data from DataList1 to DataList2 ?
If so what code would I use ?
What is the RowSource for DataList2 (another ADO data control, based on some table)? Do you want to update this table?
Yes, DataList 2 is bound to another Data Control which is linked to a different table. I want to update this table.
What are the possibilities ?
Assuming (for simlicity) both tables have only one field ("fld") which is a ListField for both DataList controls, you can try this:
If Not IsNull(DataList1.SelectedItem) Then
Adodc1.Recordset.Bookmark = DataList1.SelectedItem
Adodc2.Recordset.AddNew
Adodc2.Recordset!fld = Adodc1.Recordset!fld
Adodc2.Recordset.Update
Else
MsgBox "Please, select an item.", vbExclamation
End If
This is an idea, you can customize it for your needs.
Hope that helps. Best regards, Vlad
Thank you vlad, that was excellent.Can you help me further please ?
I have 10 names in DataList1 and I want to move 5 into DataList2 Before I update the Table linked to DataList2. How can I achieve this transfer from one DataList Box to another.
You can use batch updates, if they are supported by your database provider.
Try the following:
1. Set LockType property for Adodc2 to adLockBatchOptimistic.
2. Remove Adodc2.Recordset.Update from the click event for the button you use to transfer items from one list for another.
3. Add another button for updating Table2, put Adodc2.Recordset.UpdateBatch for the click event for this button.
You can use Adodc2.Recordset.CancelBatch to cancel updates.
Another option could be using standard list box controls instead of DataList. In this case you can fill the first list programmatically, and then, when the user transfers some items to the second list, programmatically add them to the second table.
Vlad