944,082 Members | Top Members by Rank

Ad:
Mar 26th, 2007
0

help in Sql syntax in ADODB data connenction

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
varun.coolmax is offline Offline
11 posts
since Feb 2007
Mar 27th, 2007
0

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
Reputation Points: 12
Solved Threads: 8
Junior Poster
davidcairns is offline Offline
114 posts
since Feb 2007
Mar 27th, 2007
0

Re: help in Sql syntax in ADODB data connenction

You may want to check out these Free VB6 Database Tutorials.
Reputation Points: 10
Solved Threads: 3
Light Poster
mjwest10 is offline Offline
27 posts
since Feb 2007
Mar 29th, 2007
0

Re: help in Sql syntax in ADODB data connenction

Thanx alot DAVID...That helped alot....U da man
Last edited by varun.coolmax; Mar 29th, 2007 at 4:32 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
varun.coolmax is offline Offline
11 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: similar of paintpicture
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How do I open existing excel document using vb6?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC