473,396 Members | 2,129 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.

DataKeyField with a composite key

Hi,

I was wondering how a DataGrid can handle a DataSet with a composite key.
How would I update 1 row in a database having a composite key?

A possible solution would be to concatenate my composite key in my sql
statement and then use the split function to separate again when I update.

To me this seems too complicated for its own good. Is there a simpler
solution that I could implement?

Thanks in advance.

Chris
Jul 21 '05 #1
1 1484
VB.2005 will add this.

Here is my work around. I just append an autoincrementing primarykey field
to the datatable prior to filling it from db. I use this new field in my
datagrid DataKeyField.

(Warning: this won't help push the changes back to the db using
dataadapter's Update method. I happen to be doing my updates manually.)

Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)

Dim dt As New DataTable

Dim myColumn As DataColumn = New DataColumn("MyID")
myColumn.ReadOnly = True
myColumn.DataType = System.Type.GetType("System.Int32")
With myColumn
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With
' Add the column to a new DataTable.

dt.Columns.Add(myColumn)

Dim myKey(0) As DataColumn
myKey(0) = dt.Columns("MyID")

dt.PrimaryKey = myKey

Try
da.Fill(dt)
...

HTH,
Greg

"rufus" <he***@online.de> wrote in message news:ch**********@online.de...
Hi,

I was wondering how a DataGrid can handle a DataSet with a composite key.
How would I update 1 row in a database having a composite key?

A possible solution would be to concatenate my composite key in my sql
statement and then use the split function to separate again when I update.

To me this seems too complicated for its own good. Is there a simpler
solution that I could implement?

Thanks in advance.

Chris

Jul 21 '05 #2

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

Similar topics

0
by: A frustrated developer | last post by:
I would like to find a specific row on web datagrid, locate its pageindex and itemindex, then highlight to the specific row I found. I know its datakeyfield value, is there anyway we could search...
0
by: A frustrated developer | last post by:
I would like to find a specific row on web datagrid, then highlight the row by its pageindex and itemindex on that page. I know its datakeyfield, is there a way to find the row by its datakeyfield...
0
by: A frustrated developer | last post by:
I would like to find a specific row on the web datagrid, then highlight the row by its pageindex and itemindex on that page. I know its datakeyfield, is there a way to find the row by its...
0
by: AshifToday | last post by:
this was my and my frineds little project in earlier classes, the program seperates the composite and prime numbers in two sections of the screen ===================== /* This program has...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
4
by: Ismail Rajput | last post by:
Is there any option we can use Composite DataKeyField in the DataList and DataGrid?
0
by: Adam Knight | last post by:
I have a datagrid like so: <asp:DataGrid ID="dgSubAreas" Runat="server" AutoGenerateColumns="False" DataKeyField="" DataSource='<%# Container.DataItem.Row.GetChildRows("relSubAreas") %>'> ...
1
by: rufus | last post by:
Hi, I was wondering how a DataGrid can handle a DataSet with a composite key. How would I update 1 row in a database having a composite key? A possible solution would be to concatenate my...
14
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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.