SQL Command

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
I tried to pass the textbox.text to a SQL string for query but it doesn't work, the code is the following. Thank you.

VB.NET:
[SIZE=2]SQLSTRING1 = [/SIZE][SIZE=2][COLOR=#800000]"SELECT emp_no, emp_name, nric_no, dept FROM Emp_Profile WHERE emp_name LIKE '%ToolStripTextBox1.Text%'"
[/COLOR][/SIZE]
 
Would you expect the string s to be "133" in this situation:

VB.NET:
Dim x as Integer = 100
 
Dim s as String = "123 + x/10"

??

Read the DW2 link in my signature
 
Sorry, can you be straightforward a bit, i have gone through the link but still can't get any clue. I will appreciate if you can point out the problem. Thank you.
 
You need to read up on what a string is!

Can you tell me the difference between the contents of variable S, and variable T in this code:

VB.NET:
Dim i as Integer = 10
Dim j as integer = 20
 
Dim s as String = (i+j).ToString()
Dim t as String = "i+j".ToString()

Pick one answer:

a) they are both "30"
b) they are both "i+j"
c) s is "(i+j)", t is "i+j"
d) s is "30", ti is "i+j"
e) s is "(i+j)", t is "30"


"Tell me I will forget, show me I will remember, involve me I will learn" - Chinese proverb
 
Just Try This if u r using vb 6 to vb.net 2.0 this query work

SQLSTRING1 = "SELECT emp_no, emp_name, nric_no, dept FROM Emp_Profile WHERE emp_name LIKE '" & ToolStripTextBox1.Text & "'"
 
I have made use of this code, SQLSTRING1 = "SELECT emp_no, emp_name, nric_no, dept FROM Emp_Profile WHERE emp_name LIKE '" & ToolStripTextBox1.Text & "'" ,it only returns the result with the exact name keyed in as it is stored in database but actually what i want is even when the user keys in one letter or incomplete name, it will return the result which consists of the letter or word. Thank you.
 
ok Dear Just use this query....

SQLSTRING1 = "SELECT emp_no, emp_name, nric_no, dept FROM Emp_Profile WHERE emp_name LIKE ' %" & ToolStripTextBox1.Text & " %'"


 
Aaand we start to get back to the original sql retkehing wrote (which is acually nearer to what he requires than this version)..
Suffice to say, the real problem here was that ret didnt know the difference between a string and an in-code variable, not that he couldnt write the SQL.

I'll leave you guys to it... :)
 
Back
Top