469,568 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

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 1399
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by A frustrated developer | last post: by
reply views Thread by AshifToday | last post: by
18 posts views Thread by Thomas A. Anderson | last post: by
4 posts views Thread by Ismail Rajput | last post: by
reply views Thread by Adam Knight | last post: by
1 post views Thread by rufus | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.