help in Sql syntax in ADODB data connenction

Thread Solved

Join Date: Feb 2007
Posts: 11
Reputation: varun.coolmax is an unknown quantity at this point 
Solved Threads: 0
varun.coolmax varun.coolmax is offline Offline
Newbie Poster

help in Sql syntax in ADODB data connenction

 
0
  #1
Mar 26th, 2007
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..
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2.  
  3. dim cmdcommand as new adodb.command
  4.  
  5.  
  6. With cmdCommand
  7. .ActiveConnection = conConnection
  8. .comanttext = "select * from Login where username = txusername.text"
  9.  
  10. .CommandType = adCmdText
  11.  
  12. 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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: help in Sql syntax in ADODB data connenction

 
0
  #2
Mar 27th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 28
Reputation: mjwest10 is an unknown quantity at this point 
Solved Threads: 3
mjwest10 mjwest10 is offline Offline
Light Poster

Re: help in Sql syntax in ADODB data connenction

 
0
  #3
Mar 27th, 2007
You may want to check out these Free VB6 Database Tutorials.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 11
Reputation: varun.coolmax is an unknown quantity at this point 
Solved Threads: 0
varun.coolmax varun.coolmax is offline Offline
Newbie Poster

Re: help in Sql syntax in ADODB data connenction

 
0
  #4
Mar 29th, 2007
Thanx alot DAVID...That helped alot....U da man
Last edited by varun.coolmax; Mar 29th, 2007 at 4:32 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC