DataContext ExecuteCommand() parameter substitution

556 views
Skip to first unread message

Andrus Moor

unread,
Feb 10, 2008, 12:52:47 PM2/10/08
to dbl...@googlegroups.com
DataContext ExecuteCommand() does not perform parameter substitution.

Passed parameters are silently ignored.

Andrus.

gmo...@gmail.com

unread,
Feb 10, 2008, 5:00:24 PM2/10/08
to DbLinq
Here is the MSDN page:
http://msdn2.microsoft.com/en-us/library/system.data.linq.datacontext.executecommand.aspx

But there is no example on how this should look with arguments ...
Should it look like this?
_db.ExecuteCommand("UPDATE Products SET ProductName={0}", "NewName");

or maybe like this?
_db.ExecuteCommand("UPDATE Products SET ProductName=:P0", "NewName");

Andrus Moor

unread,
Feb 10, 2008, 7:37:12 PM2/10/08
to dbl...@googlegroups.com
There is other page in MSDN which describes that syntaks looks like this:

> _db.ExecuteCommand("UPDATE Products SET ProductName={0}", "NewName");

This other page also wrote directly that string.Format() method is used to
replace {0}, {1} etc with parameters like :p0 , :p1
It seems that Format() is used to pre-process strings to create ADO .NET
syntax string with parameters :p0, :p1 etc.

There is probably typo or my misunderstanding in MSDN which describes that
parameter numbering starts with 1: {1}
MSDN samples seems to start parameters with {0}.


Andrus.

gmo...@gmail.com

unread,
Feb 12, 2008, 4:08:15 AM2/12/08
to DbLinq
I am hoping to check this in tonight.
I am editing all classes implementing IVendor.

On Feb 11, 12:37 am, "Andrus Moor" <kobrule...@hot.ee> wrote:
> There is other page in MSDN which describes that syntaks looks like this:
>
> > _db.ExecuteCommand("UPDATE Products SET ProductName={0}", "NewName");
>
> This other page also wrote directly that string.Format() method is used to
> replace {0}, {1} etc with parameters like :p0 , :p1
> It seems that Format() is used to pre-process strings to create ADO .NET
> syntax string with parameters :p0, :p1 etc.
>
> There is probably typo or my misunderstanding in MSDN which describes that
> parameter numbering starts with 1: {1}
> MSDN samples seems to start parameters with {0}.
>
> Andrus.
>
> ----- Original Message -----
> From: <gmou...@gmail.com>
> To: "DbLinq" <dbl...@googlegroups.com>
> Sent: Monday, February 11, 2008 12:00 AM
> Subject: Re: DataContext ExecuteCommand() parameter substitution
>
> > Here is the MSDN page:
> >http://msdn2.microsoft.com/en-us/library/system.data.linq.datacontext...

gmo...@gmail.com

unread,
Feb 13, 2008, 3:20:35 AM2/13/08
to DbLinq
Anrus, please sync. This should be working now.

Andrus Moor

unread,
Feb 13, 2008, 3:39:27 PM2/13/08
to dbl...@googlegroups.com
George,

> Anrus, please sync. This should be working now.

Thank you.
I tried ExecuteCommand in rev. 198 in PostgreSQL

I need to pass table name as parameter to sql command.

Got exception

Message="ERROR: 42601: syntax error at or near \"'klliik'\""
ErrorSql="select count(*) from 'klliik'"

PostgreSQL needs double quotes to quote identifiers.
DbLinq sends single quotes: 'klliik'

This is probably by design: It is not possible to use parameters for table
names.

So I will continue to use string builder to generate my queries which
require table names as parameters.

Btw. Have you looked to my composite key unit tests ?

Andrus.

gmo...@gmail.com

unread,
Feb 13, 2008, 4:20:17 PM2/13/08
to DbLinq

" Btw. Have you looked to my composite key unit tests ? "

Just checked them into a new file called CompositePK_Test.cs
Reply all
Reply to author
Forward
0 new messages