
SQL Command Drive Me Crazy !!!
Quote:
> >I have a question that made me hang around 2 day,
> >until now i still can't find the solution to fix it.
> >Following is brief description of my problem:
> > data1.RecordSource = "SELECT * FROM student WHERE level = 'Credit'"
> >Assumetion
> >----------
> >1. "data1" is the data control that already connect to the database
> >2. "student" is the table that exist inside the database
> >3. "level" is one of fields that exist inside the student table
> >From above code, the condition (level = 'Credit') is fixed and can't be
> >change when the program is running.
> >How about if i want to allow the user to enter the data then
> >i use the user entered data to search the specified record ?
> >data1.RecordSource = "SELECT * FROM student WHERE level = txtLevel.Text"
> >Assumetion
> >----------
> >1. txtLevel is the text box object that allow user to enter the data
> >SQL command seem does not allow to contain the dynamic variable in its
> >condition statement, because i code the above command but its show me the
> >error message "Too few parameter,expected 1 ". What is it mean?
> >Hope ppl whose know the solution can kindly to solve my problem, i will
> >be grateful if u able to help
> You have to separate your control property from your string, and
concatenate
> them together. IE:
> data1.RecordSource = "SELECT * FROM student WHERE level = '" _
> & txtLevel.Text & "'"
> Note that the underscore at the end of line one tells the VB IDE to regard
the
> next line as a continuation of the current line, and is not required for
string
> concatenation. You should be able to cut and paste this code.
> Hope this helps....
> Sheppe Pharis, MCP * 3/TekMetrics VB Certified
> VB5/VB6/VBS/ActiveX Developer
What if your input is an integer value?
I'm trying to get the following to work:
Dim strCriteria As String
Dim TheCartonStr As String
Dim theLotNum As Integer
strCriteria = "[Carton] = '" & TheCartonStr & "'" & " And "[LotID] =
'theLotNum"'"
Carton is a string field in a table, LotID is an Integer field in the same
table.
I can get it to work for Carton, but not for LotID.
Thanks
Jack