Getting an error when running ExecuteNonQuery() using sybase AseCommand

Viewed 157

I am getting an error when I run the writetext sql command in C# ADO.NET using the sybase provider Sybase.AdoNet4.AseClient. I have tried a lot of different things, e.g using parameterindex, named parameters, etc. Can someone please help? I am showing sample code below.

AseConnection cn = new AseConnection(connection.ConnectionString);
cn.Open();

//..... there is other code here that calls a stored procedure and gets textpointer 
// reference, but I am leaving it out to keep it short and simple

AseCommand cmd2 = new AseCommand("writetext mytable.column1 @textPointer @bigText", cn);
cmd2.CommandType = CommandType.Text

cmd2.Parameters.Add(new AseParameter("@textPointer", AseDbType.VarBinary, 16));
cmd2.Parameters["textPointer"].value = textPointerOut.value

cmd2.Parameters.Add(new AseParameter("@bigText", AseDbType.Text));
cmd2.Parameters["bigText"].value = bigText;

cmd2.ExecuteNonQuery();

cmd2.ExecuteNoQuery() throws an exception and the error is Must declare variable @textPointer

Update: If I try this syntax below, I get an error saying Incorrect sntax near '@bigText'

AseCommand cmd2 = new AseCommand("{writetext mytable.column1 @textPointer @bigText}", cn);
1 Answers

I got too stuck with passing a AseParameter to the dynamic SQL. No need to use a named parameter. Using dynamic sql, I had to do the following:

  1. Declare textPointer variable
  2. Get the pointer to the column I want to update
  3. Update column by using the the writetext command
Related