Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 31st, 2006, 02:13 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
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?
thanks
justin

Reply With Quote
  #2 (permalink)  
Old July 31st, 2006, 07:21 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Justin,

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.

Thearon
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:00 PM.


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