Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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
Thread Tools Display Modes
  #1 (permalink)  
Old January 13th, 2007, 01:53 AM
Registered User
Join Date: Oct 2004
Location: Rawalpindi, Punjab, Pakistan.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kamran Yousaf Bk
Default How to Add Primery Key value Automatically


i am working on C# Windows From Developemnt.i want to add automatically primary key value in Master and Detail Form.
Please give me idea about this.

Continusous work with commitment lead towards a new creation
Reply With Quote
  #2 (permalink)  
Old October 6th, 2007, 04:39 PM
Authorized User
Join Date: Dec 2004
Location: Swindon, Wilts, United Kingdom.
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz

Primary Keys are set on the DataTable of the data. Simply get the column and set the .Unique property as true;

//This sets a single column

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Id");
dc.Unique = true;


//This sets several columns

DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("Id1");
DataColumn dc2 = new DataColumn("Id2");

dt.Columns.Add( dc1);
dt.Columns.Add( dc2);

dt.PrimaryKey = new DataColumn[] {dc1, dc2};


Reply With Quote

Thread Tools
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
Add lines in php page automatically saifi4u PHP How-To 6 December 21st, 2006 11:13 PM
Add lines in php page automatically saifi4u PHP How-To 1 December 19th, 2006 03:42 AM
Can i use text type field in Access as primery key geetageetageeta ASP.NET 2.0 Basics 1 March 4th, 2006 08:31 AM
add row no automatically Jane SQL Language 9 June 28th, 2004 02:11 AM
When more than one field in a primery key - DGrid ManoYaka ASP.NET 1.0 and 1.1 Basics 3 January 21st, 2004 08:27 AM

All times are GMT -4. The time now is 08:23 AM.

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