views:

139

answers:

3

Hey everyone,

I'm wondering if the following SQL update query is possible using the equivalent SubSonic commands:

UPDATE MYTABLE SET MYFIELD = MYFIELD + 3 WHERE ANOTHERFIELD = ANOTHERVALUE

I couldn't find a suitable way to make a reference to the same field with the Setting object.

Any help on this will be greatly appreciated.

Regards,

Fernando

+3  A: 

You can execute this query using QueryCommand object of subsonic.

You can find similar samples over here link and link

Krunal
Thanks for the info, I think I can get it done by using the samples on the first link.
Fervelas
@Fervelas - I think you should accept answer to increase your acceptance rate. :)
Krunal
Thanks for the tip :)
Fervelas
+1  A: 

Yes - you can use "UpdateExpression" - it's a string value that you pass in with the "simple" query tool. I don't have the code or the sample in front of me - it might be "SetExpression" but it allows you to update using a string like you've entered here.

Rob Conery
I'm going to take a look at it, see if I can make it work that way, thanks!
Fervelas
A: 

Hey Rob,

I did a test using what you said on SetExpression() but somehow I'm not convinced I'm using it right.... it works but it feels (and looks) kinda funny you know?

int count = new Update(MyTable.Schema).SetExpression("MyField").EqualTo("MyField + 20")
.Where(....)

As I said, the update worked but I'm not sure if that's the intended way of doing it, and if it is (or even if it isn't), then how could I use a parameter instead of hard-coding the value in the expression.

Fervelas