Question

Locked

sql select comand in VB

By sajjad81 ·
In minr project i use that query it is workinf fine.
"select * from attend where eid=" & CLng(eid.Text)
but i can not wirte a query for two fields. i try tyo write that
"select * from attend where eid= and field2=" & CLng(eid.Text) and clng(1)
but i get a error data missmatch.
can any body helpme??

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Ah

by Tony Hopkinson In reply to sql select comand in VB

"select * from attend where eid=" & CLng(eid.Text) & " and field2=" & clng(1)

Collapse -

Look at the result of the concatenation ...

by etruss In reply to Ah

Your phrases were out of order. Your attempt: "select * from attend where eid= and field2=" & CLng(eid.Text) and clng(1)
results in: "select * from attend where eid= and field2=" & True

Also, you want a string when you are done so you don't need to convert anything to Long. So use this instead:

select * from attend where eid=" & eid.Text & " and field2=1"

Collapse -

True but the convert to long

by Tony Hopkinson In reply to Look at the result of the ...

does have the advantage of killing an injection attack.

Which is precisely why parameterised queries should be used for 'user' entered data.

Collapse -

Missing parameter

by mdv3441 In reply to sql select comand in VB

Given the statement;
"select * from attend where eid= and field2=" & CLng(eid.Text) and clng(1)

eid= What no parameter.

Collapse -

Isn't this clearer to read ?

by marc In reply to Missing parameter

Why don't you use brackets - it's sure easier to read...

Result = "select * from attend where (eid=" & eid.Text & ") AND (field2=1)"

Greetings.

Collapse -

Handy suggestion

You may also want to peruse through all of your code and look for any typos and spelling errors, something tells me that is a good place to start...

Collapse -

Regarding to your SQl query

by Mitras_saikat In reply to sql select comand in VB

hi,
your query is
"select * from attend where eid= and field2=" & CLng(eid.Text) and clng(1)

I have made a correction
"select * from attend where eid=" & CLng(eid.Text) & " and field2=" & clng(1) & ""

or you can write

"select * from attend where eid=" & CLng(eid.Text) & " and field2=1"


Check the query now

Back to Web Development Forum
8 total posts (Page 1 of 1)  

Software Forums