how to debug.print sql statement with parameter values?

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Dim da As New sqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.Selectcommand.CommandText = "Select * From tbl1 Where fld1 = @P"
da.SelectCommand.Parameters.Add("@P", SqlDBtype.varchar, 50, "fld1")
da.SelectCommand.Parameters("@P").Value = txt1.Text

lets say that txt1.Text = "test"

Console.WriteLine(da.SelectCommand.CommandText)

-->returns

Select * From tbl1 Where fld1 = @P

Is it possible to debug.print the sql statement to return with the
Paramenter value?

Select * From tbl1 Where fld1 = 'test'

How to do this?

I am thinking something similar to

console.WriteLine("Select * From tbl1 Where {0}", param0")

my actual statement has several parameters.

thanks,
Rich
 
Incase anyone cares -- I ended up doing the debug.print ("Select ...Where
fld1 Like '{0}' And fl2 Like '{1}'...)", p(0), p(1), ...)

Where I loop through the parameter collection and store the param values in
a string array called p. I was just checking if there were already a builtin
way to do this. I guess not.
 
Back
Top