Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 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 January 13th, 2007, 02:53 AM
Registered User
 
Join Date: Oct 2004
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

Hello..........

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
 
Old October 6th, 2007, 04:39 PM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

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;

dt.Columns.Add(dc);

//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};

Regards,

Dom





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add lines in php page automatically saifi4u PHP How-To 6 December 22nd, 2006 12:13 AM
Add lines in php page automatically saifi4u PHP How-To 1 December 19th, 2006 04:42 AM
Can i use text type field in Access as primery key geetageetageeta ASP.NET 2.0 Basics 1 March 4th, 2006 09: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 09:27 AM





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