473,396 Members | 1,859 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.

adding a primary key to a dataset/datatable

I have a need to add a primary key to a dataset/datatable. How can this be
done using a standard oledb data provider?

Tx for any help.
Nov 21 '05 #1
10 27794
OleDataAdapter should have primary key in its select command/statement,
for e.g Select Employee_ID from employees

Then use fill command to fill the dataset

OleDataAdapter.Fill(Dataset)
thats it, you'll have primary key in ur dataset
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
I have a need to add a primary key to a dataset/datatable. How can this be
done using a standard oledb data provider?

Tx for any help.

Nov 21 '05 #2
Hi Arsalan.

I am working with vfp free tables - there are no primary keys in the
original tables and they can't be added to the backend (because they are not
mine and adding a column would screw them up).

Bernie

"Arsalan" <ar***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
OleDataAdapter should have primary key in its select command/statement,
for e.g Select Employee_ID from employees

Then use fill command to fill the dataset

OleDataAdapter.Fill(Dataset)
thats it, you'll have primary key in ur dataset
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
I have a need to add a primary key to a dataset/datatable. How can this
be done using a standard oledb data provider?

Tx for any help.


Nov 21 '05 #3
If the table structure doesn't contain primary key then its impossible to
add it to the dataset.
How about making a column alias from two or more columns [like composite
primary key] that would make it possible to select records from the table,
it all depends on what kind of column u have in ur database table

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:uv*************@TK2MSFTNGP15.phx.gbl...
Hi Arsalan.

I am working with vfp free tables - there are no primary keys in the
original tables and they can't be added to the backend (because they are
not mine and adding a column would screw them up).

Bernie

"Arsalan" <ar***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
OleDataAdapter should have primary key in its select command/statement,
for e.g Select Employee_ID from employees

Then use fill command to fill the dataset

OleDataAdapter.Fill(Dataset)
thats it, you'll have primary key in ur dataset
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
I have a need to add a primary key to a dataset/datatable. How can this
be done using a standard oledb data provider?

Tx for any help.



Nov 21 '05 #4
I assume you are asking to add a primary key just for processing while
the dataset/datatable is in memory and aren't trying to write it back
out anywhere.

You can add a primary key by using the PrimaryKey property on a
DataTable

You can use the following code as an example:

Dim lds as DataSet = GetSomeDataSet()

For Each ldt As DataTable In lds.Tables
ldt.PrimaryKey = New DataColumn() {ldt.Columns("ColumnName")}
Next

-------

A couple things to note here. This iterates through each datatable
that's returned in the dataset, you can run the line inside the
for..each by itself if you only want to create a PrimaryKey for just one
table.

Also, if you want to make a multi-column primary key then the line
inside the for..each would look something like this:

ldt.PrimaryKey = New DataColumn() _
{ldt.Columns("ColumnName1"), ldt.Columns("ColumnName2")}

Hopefully this makes sense...

Brian Swanson
I am working with vfp free tables - there are no primary keys in the
original tables and they can't be added to the backend (because they are


Nov 21 '05 #5
One other note...

When adding the primary key in this way the system doesn't automatically
set the column you assign to the primary key as unique. You have to do
this as well by using:

ldt.Columns("ColumnName").Unique = True
---
Brian Swanson
"Brian Swanson" <pu*******@gREMOVETHISmail.com> wrote in message
news:pu*******@gREMOVETHISmail.com:
I assume you are asking to add a primary key just for processing while
the dataset/datatable is in memory and aren't trying to write it back
out anywhere.

You can add a primary key by using the PrimaryKey property on a
DataTable

You can use the following code as an example:

Dim lds as DataSet = GetSomeDataSet()

For Each ldt As DataTable In lds.Tables
ldt.PrimaryKey = New DataColumn() {ldt.Columns("ColumnName")}
Next

-------

A couple things to note here. This iterates through each datatable
that's returned in the dataset, you can run the line inside the
for..each by itself if you only want to create a PrimaryKey for just one

table.

Also, if you want to make a multi-column primary key then the line
inside the for..each would look something like this:

ldt.PrimaryKey = New DataColumn() _
{ldt.Columns("ColumnName1"), ldt.Columns("ColumnName2")}

Hopefully this makes sense...

Brian Swanson
I am working with vfp free tables - there are no primary keys in the
original tables and they can't be added to the backend (because they
are


Nov 21 '05 #6
Hi Brian,

I looked at a couple of books I have on my shelf and figured this out, but
thank you.

Unfortunately, I do want to write it back to the backend, and, as luck would
have it, this does me absolutely no good! (as your caveat suggested). But
thanks for responding.

Bernie

"Brian Swanson" <pu*******@gREMOVETHISmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One other note...

When adding the primary key in this way the system doesn't automatically
set the column you assign to the primary key as unique. You have to do
this as well by using:

ldt.Columns("ColumnName").Unique = True
---
Brian Swanson
"Brian Swanson" <pu*******@gREMOVETHISmail.com> wrote in message
news:pu*******@gREMOVETHISmail.com:
I assume you are asking to add a primary key just for processing while
the dataset/datatable is in memory and aren't trying to write it back
out anywhere.

You can add a primary key by using the PrimaryKey property on a
DataTable

You can use the following code as an example:

Dim lds as DataSet = GetSomeDataSet()

For Each ldt As DataTable In lds.Tables
ldt.PrimaryKey = New DataColumn() {ldt.Columns("ColumnName")}
Next

-------

A couple things to note here. This iterates through each datatable
that's returned in the dataset, you can run the line inside the
for..each by itself if you only want to create a PrimaryKey for just one

table.

Also, if you want to make a multi-column primary key then the line
inside the for..each would look something like this:

ldt.PrimaryKey = New DataColumn() _
{ldt.Columns("ColumnName1"), ldt.Columns("ColumnName2")}

Hopefully this makes sense...

Brian Swanson
> > I am working with vfp free tables - there are no primary keys in the
> > original tables and they can't be added to the backend (because they
> > are

Nov 21 '05 #7
Bernie,

What is it you want to achieve setting a primary key in the tables of your
foxpro database.
Or use as Brian wrote use it internally by instance to set a relation.

For me it is as well not clear which of the two it is (because I have readed
your previous questions).

Cor
Nov 21 '05 #8
Hi Cor,

I tried it, and it doesn't achieve my goal. I was hoping that it would
somehow enable me to update the back end more effectively, but it did not.

Bernie

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u5**************@TK2MSFTNGP15.phx.gbl...
Bernie,

What is it you want to achieve setting a primary key in the tables of your
foxpro database.
Or use as Brian wrote use it internally by instance to set a relation.

For me it is as well not clear which of the two it is (because I have
readed your previous questions).

Cor

Nov 21 '05 #9
Bernie,

Your goal is not clear in my opinion.

Do you want to set the keys in the database
Or
Do you want to set the primary keys in the dataset.

Where I assume setting the primary keys in the database using the SQL Alter
command and the

http://msdn.microsoft.com/library/de...able___sql.asp

the SQLcommaned.executenonquery to process that.

:-)

Cor
Nov 21 '05 #10
Hi Cor,

The problem with that is, I am not allowed to alter the tables - they belong
to a third party. I am simply hooking into them.

I've come to the conclusion that I will only be able to do this by using the
foxpro environment itself, but I probably won't have to - it appears my
client will be happy with 'view access' only, so I can hook in, gather the
data I need, and display it.

Tx for your help.

Bernie

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ep*************@TK2MSFTNGP14.phx.gbl...
Bernie,

Your goal is not clear in my opinion.

Do you want to set the keys in the database
Or
Do you want to set the primary keys in the dataset.

Where I assume setting the primary keys in the database using the SQL
Alter command and the

http://msdn.microsoft.com/library/de...able___sql.asp

the SQLcommaned.executenonquery to process that.

:-)

Cor

Nov 21 '05 #11

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

Similar topics

3
by: DaveF | last post by:
I have a dataset with an unknown amount of fields. The user can choose a nuber of numeric fields in that datatable. I am making a chart out of those fields. I need to know the minimum and maximun...
4
by: paul | last post by:
Hi, Im trying to add a dataset to the app_code directory using vs2005 \ SQL2005 beta 2. When I run through the wizard I select the option to auto create new Stored Procedures (Select, update,...
1
by: abc my vclass | last post by:
Is VS2005 debugger let me to see dataset, datatable data as table form? I found if I watch some table or dataset variable is very very hard to see. Is there any good tools or add-ins for debugger...
0
by: AboutJAV | last post by:
Hi, I added a datagrid. When the user make changes to the cells, the datatable was updated with the new values. I need to update the dataset.datatable with the current datatable, but an error...
2
by: Mr. Arnold | last post by:
I am working a C# project that uses what's in the subject. I kind of have the basics down on reading the table data. I don't use the above methods of data access or persistence, but I am stuck...
1
by: Daniel Jeffrey | last post by:
..Net 2.0 VStudio 2005 C# I know this is going to seem like a strange question, as even I am sure I have missed something - but I cant find it. I want a simple event on any of the objects...
1
nev
by: nev | last post by:
dataset.datatable.adddatatablerow("john", "rambo") datatabletableadapter.update(dataset.datatable) when i view my mysql table using navicat, the row was not added. i tried adding...
3
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the...
4
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a DataSet with one table filled. From this DataSet (DataTable), I need to create a SqlDataReader. Does anybody knows how to do this ? Is it possible ?? Thanks for any help.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.