Re: Commandtext using an @parametername but not with a stored procedure
- From: "John Dohn" <noemail@xxxxxxxxxxx>
- Date: Wed, 27 Feb 2008 07:39:12 -0500
Good ole sp_execute. That explains it. Thanks.
"Andrew J. Kelly" <sqlmvpnooospam@xxxxxxxxxxxx> wrote in message
news:O6U1x9MeIHA.4396@xxxxxxxxxxxxxxxxxxxxxxx
If you look at what is happening using profiler you will most likely see
that the normally adhoc call was turned in to a sp_executesql call
instead. sp_executesql can make use of parameters and helps to reuse the
query plans. By specifying parameters for adhoc statements you can give it
the best chance (short of a sp) to reuse query plans.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"John Dohn" <noemail@xxxxxxxxxxx> wrote in message
news:u31aqTMeIHA.4196@xxxxxxxxxxxxxxxxxxxxxxx
I have seen example vb.net 1.1 code that uses a commandtext string that
includes a parameter. The commandtype is commandtype.text, not a SP. I did
not know it was possible to do this. I would like to understand what is
going on here and exactly how the use of parameters works when using a
commandtype of text rather than a SP. For example, Who is receiving the
parameter values if there is no SP to catch them?
Thanks in advance for your help. Here is the relevant code:
Dim cmdUpdate as SqlCommand = cnn.createcommand
cmdUpdate.commandtype = commandtype.text
cmdUpdate.commandtext= "UPDATE Customers SET ContactName = @ContactName
WHERE CustomerID = @CustomerID"
The code then goes on to add various parameters to cmdUpdate.
e.g.
cmdUpdate.Parameters.Add("@ContactName", sqldbtype.Nvarchar, 30,
"ContactName")
And sets the command for the dataadapter...
da.UpdateCommand = cmdUpdate
And specifies which version of the dataset data to use...
cmdUpdate.parameters("@CustomerID").SourceVersion =
DataRowVersion.Original
Then goes on to fill the dataset, gets a particular datarow to edit,
makes sure there is some data there and then as exï¶ì(ed saves the
changes with
da.Update(ds, "Customers")
.
- References:
- Commandtext using an @parametername but not with a stored procedure
- From: John Dohn
- Re: Commandtext using an @parametername but not with a stored procedure
- From: Andrew J. Kelly
- Commandtext using an @parametername but not with a stored procedure
- Prev by Date: Re: Commandtext using an @parametername but not with a stored procedure
- Next by Date: problem with getdate()
- Previous by thread: Re: Commandtext using an @parametername but not with a stored procedure
- Next by thread: problem with getdate()
- Index(es):
Relevant Pages
|
Loading