Actually, it's the same answer to handle
O'Brien and avoid SQL Injection.
(1) Use a stored procedure and parameters. Fixes both problems.
(2) Use your existing code, but create the string for the SQL thus:
Code:
str = "select username,password from login_form " _
& " where username='" & Replace(TextBox1.Text,"'","''") & "' " _
& " and password = '" & Replace(TextBox2.Text,"'","''") & "'"
You just convert every apostrophe you find into a pair of apostrophes. With a simple query like that, you have fixed both problems.