Last post Aug 31, 2011 10:34 AM by Dan Bracuk
Aug 30, 2011 09:32 AM|Dan Bracuk|LINK
Has anyone ever accomplised this? Sample code is at the bottom and I'm either doing something wrong or attempting something unachievable. Hopefully it's the former. I'm very new at dot net.
I am using redbrick odbc driver version 5.63.0010. We also have this driver installed on a ColdFusion server where we can run parameterized queries.
The code below runs successfully. However, if I uncomment the line where I attempt to use the @Code parameter, I get this exception:
** ERROR ** (87) Invalid syntax '...SERVICE WHERE SERVICE_CODE=<==>@'.
This is the same error I get if I run that query against the database outside of dot net. So, what's wrong with this code?
static void Main(string args)
string DWConnectionString =
string DWQuery = "select count(*) TheCount from service where service_code = 20";
// DWQuery = "select count(*) TheCount from service where service_code = @Code";
OdbcConnection DWConnection = new OdbcConnection();
DWConnection.ConnectionString = DWConnectionString;
OdbcDataAdapter DWDataAdaptor = new OdbcDataAdapter();
OdbcDataReader DWDataReader = null;
OdbcCommand DWCommand = new OdbcCommand(DWQuery, DWConnection);
OdbcParameter MyParam = new OdbcParameter("@Code", OdbcType.SmallInt);
DWDataReader = DWCommand.ExecuteReader();
Console.WriteLine("hello " + DWDataReader["TheCount"].ToString());
catch (Exception ex)
Aug 31, 2011 10:34 AM|Dan Bracuk|LINK
Fortunately, it was bad code on my part. This reference,
http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx, says that System.Data.ODBC only support positional parameters. Bit of a pain, but at least I can do it.