[python-win32] ADO and LIKE statements in python
ram at ramsundar.com
ram at ramsundar.com
Wed Jan 18 18:32:06 CET 2006
Helo guys,
I am trying to query the MSSQL DB using ADO.
I am not able to make the LIKE statement fetch the correct results.
Can anyone tell me what I need to do to get this working?
Below is the code snippet:
import win32com.client
const = win32com.client.constants
#conn = establish SQL connection
cmd = win32com.client.Dispatch("ADODB.Command")
cmd.ActiveConnection = conn
name = '@fname'
value = "'raj"
p=cmd.CreateParameter(name, const.adVarchar, Value=value)
cmd.Parameters.Append(p)
cmd.CommandText = \
"SELECT * FROM tb_name WHERE firstname LIKE @fname"
cmd.CommandType = const.adCmdText
(rs, dummy) = cmd.Execute()
while not rs.EOF:
print rs.Fields('firstname').Value
rs.MoveNext()
rs.Close()
I originally was using the '%?%' symbol but that did not work and now,
i changed it to @fname but this returns a traceback telling that I need
to declare @fname.
Also, I have another probelm with using the "IN" SQL statement.
I appreciate your help in advance,
Thank you,
Raja Raman
More information about the Python-win32
mailing list