ADO Command SQL Statement w/ variable *Resolved*
Sry if the title of the thread sucks but I am creating a command incode for my program and I am not sure if I wrote it quite right as i am not sure of how to add a variable to a SQL statement in VB so here is the code can you tell me if it is done right please.
Thx in advance
VB Code:
With m_adoCommandAR
.CommandText = "SELECT Square_Name0, Square_Name1, Square_Name2, " & _
"Square_Name3, Square_Name4, Square_Name5, " & _
"Square_Name6, Square_Name7, Square_Name8, " & _
"Square_Name9, FROM Areas WHERE Area_Name = " & _
RoomName 'The variable
.CommandType = adCmdText
.ActiveConnection = m_adoConnection
End With
Re: ADO Command SQL Statement w/ variable
VB Code:
With m_adoCommandAR
.CommandText = "SELECT Square_Name0, Square_Name1, Square_Name2, " & _
"Square_Name3, Square_Name4, Square_Name5, " & _
"Square_Name6, Square_Name7, Square_Name8, " & _
"Square_Name9, FROM Areas WHERE Area_Name = '" & RoomName & "';"
'The variable
.CommandType = adCmdText
.ActiveConnection = m_adoConnection
End With
I just put a single quote around RoomName. If the variable is a string, then put single quotes around it, else if it's a numeric value, then don't put any quotes around it.
HTh