|
-
Jan 23rd, 2004, 09:23 AM
#1
Thread Starter
Member
sql query syntax in .net
i have the following query but it doesnt produe any results:
Me.OleDbCommand1.CommandText = "Select * From Emp Where Week='WeekString'"
is this valid syntax when using the WHERE part of a sql query
WeekString is just a string that takes its value from a txtbox on a form
-
Jan 23rd, 2004, 09:31 AM
#2
Re: sql query syntax in .net
Try this:
Me.OleDbCommand1.CommandText = "Select * From Emp Where Week='" & WeekString & "'"
BTW, this is the VB6 forum. We're old timers.
-
Jan 23rd, 2004, 10:30 AM
#3
The frog's got the right idea, not that his code is easy to read or anything. You have to enclose a string argument in quotes, which he has done, but you have to look kind of close to count those hash marks. I prefer to surround it with the character code, just for readability, though it is slower to type:
"SELECT * FROM Emp WHERE Week = " & chr(34) & WeekString & chr(34)
instead of
"Select * From Emp Where Week='" & WeekString & "'"
-
Jan 23rd, 2004, 10:33 AM
#4
Let me in ..
I do not think so. According to him WeekString itself is a string and not a variable containing string. So what he is doing is correct.
"Select * from Blah Where Blah = 'WeekString' " is perfectly fine.
-
Jan 23rd, 2004, 10:36 AM
#5
Originally posted by techyspecy
I do not think so. According to him WeekString itself is a string and not a variable containing string. So what he is doing is correct.
"Select * from Blah Where Blah = 'WeekString' " is perfectly fine.
WeekString is just a string that takes its value from a txtbox on a form
-
Jan 23rd, 2004, 10:46 AM
#6
OK, so the principle is that if it is a string variable, then it must be enclosed in quotes with a technique like froggies (faster and easier) or mine (slower, but more legible). If it is not a variable, then you don't have to do that, as techyspecy stated.
That ought to answer the question with due thoroughness.
-
Jan 23rd, 2004, 10:53 AM
#7
Good.
Now let's all live happily ever after.
-
Jan 23rd, 2004, 11:05 AM
#8
Not quite EVER after, thanks. I'll get pretty wrinkly eventually.
-
Jan 23rd, 2004, 11:09 AM
#9
Thread Starter
Member
thanks guys, both of what u have said makes interessting reading and gives me some stuff to think about.
-
Jan 23rd, 2004, 12:35 PM
#10
Frenzied Member
FWIW, IMHO using parameters makes for cleaner and easier to read/maintain code. e.g.:
VB Code:
cmd.CommandText = "INSERT INTO RadioMessages (Unit, Code, Message, Call, [User]) VALUES (@Unit, @Code, @Message, @Call, @User)"
cmd.Parameters.Clear()
cmd.Parameters.Add("@Unit", unitGUID)
cmd.Parameters.Add("@Code", code)
cmd.Parameters.Add("@Message", message)
cmd.Parameters.Add("@Call", callGUID)
cmd.Parameters.Add("@User", user)
cmd.ExecuteNonQuery()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|