how to debug.print sql statement with parameter values?

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
 
R

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top