Re: SQL Commad Parameter variations
From: Brian Sabino [MS] (briansa_at_online.microsoft.com)
Date: 03/04/04
- Next message: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Previous message: Ryan Chapman [MSFT]: "Re: Prevent keydown event to continue in list control"
- In reply to: Zahid: "SQL Commad Parameter variations"
- Next in thread: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Reply: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 4 Mar 2004 13:41:13 -0800
Method 2 is superior. In method 1 you're giving the provider only a name
and an Object. The provider has to infer the SqlDbType, and it can't always
infer the correct type. In method 2 you're creating a parameter and setting
the parameter type, so there is no guessing done by the provider.
There is a bug in .prepare() where you can in some cases lose the first set
of values in the parameter collection. I believe if you set actual values
into the parameters then call prepare() you'll lose the values, but if you
setup your parameter collection then call prepare() and then set your values
it works properly. In any event calling prepare() is purely optional. If
you don't call prepare the command will be prepared for you on first
execution. The only time you would want to use prepare() explicitly is if
you already have your commands set up, and you have some extra idle time in
your app. In this case calling prepare while your app would otherwise be
idle will save you some time during the first execution of your commands.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Zahid" <mrzsbutt@hotmail.com> wrote in message
news:CAC8C5F1-7F50-40FD-981F-218443E34293@microsoft.com...
> Hi,
>
> If I use:
>
> (Method 1)
> gMyCommand.Parameters.Add("@ItemNo", 450)
>
> or use:
> (Method 2)
> gMyCommand.Parameters.Add(New SqlCeParameter("ItemNo", SqlDbType.int))
> gMyCommand.Parameters("ItemNo").Value = 450
>
> Are there any performance differences? Ive read previous threads that
state Method 1 doesnt always work.
> Also, there is some confusion from previous threads whether to use
"SQLCeCommand.prepare()". Some say it should be used and other say dont use
it - simply call "SqlCeCommand.executeNonQuery" ....:-\ Confusing...
>
> Does it work/Act diffently on different processors or something?
>
> All comments are greatly appreciated. Thanks in advance.
>
- Next message: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Previous message: Ryan Chapman [MSFT]: "Re: Prevent keydown event to continue in list control"
- In reply to: Zahid: "SQL Commad Parameter variations"
- Next in thread: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Reply: Jon Skeet [C# MVP]: "Re: SQL Commad Parameter variations"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|