1

I have a function that accepts an SQL statement like this:

Public ExecuteReader(ByVal strSQL As String)
    Dim objCommand as New SQLCommand(strSQL)
End Public

The previous developer concatenated strings like this (prone to SQL injection, I know):

SELECT * FROM Person WHERE ID = " & intID & "

I am now using SQL parameters e.g. strSQL could now be

SELECT * FROM Person WHERE ID = @ID

The only option I believe is to have the calling function add the parameters and pass the parameter values to ExecuteReader i.e.

Public ExecuteReader(ByVal strSQL As String, ByVal params as dbParameter)

Is there an easier way of doing this?

1 Answer 1

1

I think the only way would be to use

addWithValue("@ID", value)

I don't think there's an easier way...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.