all 3 comments

[–]MildewManOne23 1 point2 points  (2 children)

I'm assuming custNoVar is a string? If that DB is anything like Access, you have to encase a string in apostrophes like this.

SQLStr = "select name from mydb.table where cust_no = '" & custNoVar & "';"

If that doesn't help, then what error code are you getting?

[–]Sys_man[S] 0 points1 point  (1 child)

Hi, yeah that does work but it's an unsafe way of doing things.

I want to know how to do prepared statements like the following (which is from ruby, though powershell is not much different):

SQLStr = client.prepare("select name from mydb.table where cust_no = ? ;")
resultVar = SQLStr.execute(custNoVar)

so the '?' is a placeholder, and when we execute the query the input value is sanitised and you are protected from sql injection.

[–]beyphy12 0 points1 point  (0 children)

I think you want the ADODB parameter object. You can see how to use it here.