CommandBuilder Question...

  • Thread starter Thread starter MobileBoy36
  • Start date Start date
M

MobileBoy36

Hi group,

I'm using CF 2.0 (VS 2005) and SQLCE 3.0.

- My table looks like:

create table Action
(
ActionId nvarchar(10) not null,
Description nvarchar(25) not null,
constraint Action_PK primary key (ActionId)
);


- My sub looks like:

Public Sub ADAPTERTEST()
Dim DataAdapter As SqlServerCe.SqlCeDataAdapter
Dim CommandBuilder As SqlServerCe.SqlCeCommandBuilder

DataAdapter = New SqlServerCe.SqlCeDataAdapter("Select ActionId,
Description from Action", _Db.DbConnection)
CommandBuilder = New
System.Data.SqlServerCe.SqlCeCommandBuilder(DataAdapter)

DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand
DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand
DataAdapter.DeleteCommand = CommandBuilder.GetDeleteCommand
End Sub

- My question:

The commandbuilder generates the following UpdateQuery:

UPDATE [Action] SET [ActionId] = @p1, [Description] = @p2
WHERE (([ActionId] = @p3) AND ([Description] = @p4))

Description is not part of the PK_key...
So why is ([Description] = @p4)) part of the where clause?
How can I prevent the commandbuilder adding it to the where clause?
So that the updatequery looks like:

UPDATE [Action] SET [ActionId] = @p1, [Description] = @p2
WHERE ([ActionId] = @p3)

Or, what do I have to do If I don't can/want specify @p4?

Best regards,
Mobile boy
 
In < 2005 you were stuck, one of the inherent flaws. There's a
ConflictOption in the new framework that gives you some more control

cb.ConflictOption = ConflictOption.OverwriteChanges

The bad news through is that ConflictOption isn't supported in the CF 2.0
AFAIK. As such, you're going to have to roll your own update logic. If
you're using the full framework you can use it, but otherwise I think you're
out of luck.



HTH,



Bill
 
If command builder can't build appropriate command (which is pretty common
unless select query looks like "Select * from MyTable"), you could use your
own Insert/Update/Delete commands instead of command builder.


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Back
Top