Re: SQL Commad Parameter variations

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Brian Sabino [MS] (briansa_at_online.microsoft.com)
Date: 03/04/04


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.
>


Relevant Pages

  • Re: membership provider
    ... the user only if the user exists in the DB then doing a redirect to the next ... When I stepped through the current app I noticed what he's doing just on the ... running 7 more queries to pull data and put into a user object then passing ... I think your login screen needs to use the custom provider.. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to Change MinRequiredNonAlphanumericCharacters in AspNetSq
    ... Dominick Baier - DevelopMentor ... If I modify the existing provider in my app, do the changes apply only to my app? ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Argh! Provider is no longer available! Please help!
    ... apps can easily get to it, and the data is tabular, so adding an OLE DB ... provider into my app seemed like the way to go. ... So I cranked up Visual Studio 6 and selected Insert, New ATL Object, Data ... I do have to run the app first (I haven't figured out ...
    (microsoft.public.data.oledb)
  • Re: Logging database changes
    ... That separates ... The idea is to get the app doing as ... Use code like this for file operations: ... It essentially makes the application a client to a data provider. ...
    (comp.databases.pick)
  • Re: Any suggestions with this updated code????
    ... "The OLE DB Provider for Oracle supports multiple parameter sets on the ... The Oracle provider supports input parameters in SQL ... On procedure-call commands, this provider supports ...
    (microsoft.public.vb.database.ado)