Wrox Programmer Forums
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 31st, 2006, 02:13 PM
Authorized User
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Primary key

How do i add a primary key to my datatable through code in design time?
the reason i ask is that i am trying to take advantage of the disconnected architecture of ado.net (i am populating a dataset with a table of items(inventory), and the items are put into a listbox where a user can select one item to display the details on the item. the only way i can figure out how to fill text boxes with the corresponding selected item details is by doing a filter of the original dataset (filter by 'id' which is what i set as the data value for the listbox) using the unique 'id' column and then setting the text fields of these text boxes to the corresponding columns in the datatable row that is returned after the filter. this way i wont have to reconnect to the database and query for the listbox selected item by 'id'.
the problem here is that you have to have a primary key defined in your datatable before you can filter it....i have tried a few methods of adding a primary key at design time with code but have been unsuccessful....any help please? is this sound practice to avoid requerying the database, even if its a stored procedure? i figured it would be best practice to use the dataset in memory and just filter it?

Old July 31st, 2006, 07:21 PM
Thearon's Avatar
Wrox Author
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts


Does your inventory table have a primary key defined on it? I would assume that it does and you should also be selecting that primary key in your dataset. If you are binding a listbox to a DataTable, then you really should only have two columns in the DataTable; the primary inventory key and the inventory description.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
primary key problem Abhinav_jain_mca SQL Server 2000 1 September 2nd, 2004 08:11 AM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.