DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   help in Sql syntax in ADODB data connenction (http://www.daniweb.com/forums/thread73471.html)

varun.coolmax Mar 26th, 2007 6:03 pm
help in Sql syntax in ADODB data connenction
 
I am using a ADODB connection to connect to an access database and am using an SQL string as the comandtext....but i need to check the validity of wat i have typed.....here is the sql statement..


dim cmdcommand as new adodb.command


With cmdCommand
.ActiveConnection = conConnection
.comanttext = "select * from Login where username = txusername.text"

.CommandType = adCmdText

End With

here i want to encorporate the use of check for a text feild...am i using the right Sql syntax here....as in can i jus refer to txtusername.text or do i have to use it like $txtusername.text or soemthing.....Plzz Help

davidcairns Mar 27th, 2007 10:51 am
Re: help in Sql syntax in ADODB data connenction
 
For starters lets look at the SQL statement line

.comanttext = "select * from Login where username = txusername.text"

This is not using the textbox value, the correct syntax for using the control is

.comanttext = "select * from Login where username = " & txusername.text

This still has a problem as SQL requires quote delimiters for string fields, hence we would add that to the string thus

.comanttext = "select * from Login where username = '" & txusername.text & "'"

And finally to safely pass this without allowing for a SQL injection attack we would ensure the textbox has no apostrophy that could damage the database

.comanttext = "select * from Login where username = '" & replace(txusername.text, "'", "''") & "'"

That should just about do it

D

mjwest10 Mar 27th, 2007 10:23 pm
Re: help in Sql syntax in ADODB data connenction
 
You may want to check out these Free VB6 Database Tutorials.

varun.coolmax Mar 29th, 2007 4:32 pm
Re: help in Sql syntax in ADODB data connenction
 
Thanx alot DAVID...That helped alot....U da man


All times are GMT -4. The time now is 1:51 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC