473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

the best way to set the primary key in a datatable or dataset

Hi

im hoping someone can provide or point to an code example of the best
(ie easiest quickest minimal code) way of setting the primary key of a
datatable or dataset targeted to .Net 3.5.

The dataset/datatable would either be already existing OR at the point
of created when the primary key is set

The code examples i found on the net seem to be overly convoluted for
what i would think was something easily set using a property or
something, or am i silly to think this

Peted
Sep 15 '08 #1
1 1553
"Peted" wrote in message news:7g********************************@4ax.com...
im hoping someone can provide or point to an code example of the best
(ie easiest quickest minimal code) way of setting the primary key of a
datatable or dataset targeted to .Net 3.5.

The dataset/datatable would either be already existing OR at the point
of created when the primary key is set

The code examples i found on the net seem to be overly convoluted for
what i would think was something easily set using a property or
something, or am i silly to think this
It's reasonably easy. You just add the column or columns to the
PrimaryKey property of the datatable:

theDataTable.PrimaryKey = new DataColumn[]{theDataTable.Columns[0]};
Sep 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim Heavey | last post by:
Hello, I have done a little VB Programming and now I am giving C# a try. Right now I am working with Dataset and DataTables and there are a couple of compile errors that I would work in VB, but are...
1
by: Somebody_Out_There | last post by:
Hello, I am trying to create a strongly typed datatable/dataset from an untyped dataset or datatable returned from a stored proc. The structure of the table cannot be static since the results...
1
by: Romao | last post by:
Hi, None of the C#/ADO documentation I was able to read refers what are the best practices/implementations for this "kind of" problem, I would like to get help/opinions please, let me explain...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
1
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have...
1
by: Tom W | last post by:
code snipped from MS sample "N-Tier Data Form and Data Layer" example (101 vb.net samples). Public Class frmMain Private dsSupplierProducts as DataSet Private dtSupplier as DataTable Private...
2
by: Aryan | last post by:
Hi, I am implementing Business object, but while implementing this I want to have DataTable or DataSet as part of Business Object. For example, I want to bind controls directly to these Business...
0
by: riyap | last post by:
Hi i have a question regarding a update in msaccess DB using string builder,DATA SET AND DATA RELATIONS can we do that in access DB i have a table in access i need to pass more than 1 record and...
5
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have a Datatable/Dataset that I'd like to update back to the server. How do I go about saving changes to my Datatable or Dataset back to the database?
5
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.