Commandtext using an @parametername but not with a stored procedure



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")





.



Relevant Pages

  • Re: Commandtext using an @parametername but not with a stored procedure
    ... 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. ... 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. ... The code then goes on to add various parameters to cmdUpdate. ...
    (microsoft.public.sqlserver.connect)
  • Re: Commandtext using an @parametername but not with a stored procedure
    ... that the normally adhoc call was turned in to a sp_executesql call ... The commandtype is commandtype.text, not a SP. ... The code then goes on to add various parameters to cmdUpdate. ... And specifies which version of the dataset data to use... ...
    (microsoft.public.sqlserver.connect)

Loading