Las consultas ASP.NET no cambian con cadenas y parámetros

I am running queries as a string that has a single parameter (and is changed) but am getting some odd behavior. Here is the code:

              WHERE NAMESPACE_PREFIX = '" + prefix + "' AND GENERIC_SCHEMA = 1";

Response.Write(cmd + "<br>");

using (SqlDataReader elementReader = elementDB.executeCommand(cmd))
    while (elementReader.Read())
        Response.Write(cmd+ elementReader["RID"].ToString() + "<br>");

Lo que espero que suceda:

Programas de Response.Write executes two times and the the data is identical.

Qué está pasando realmente:

The elementReader appears to 'memorize' the first value of prefix. When the 'prefix' variable changes, the Response.Write outside the SQL statement is correctly outputting the string, however the while loop inside the SQL statement does not execute at all. However, whenever 'prefi'x comes back to the first value it was set to, the statement DOES execute.

I am at a complete loss as to why this is happening and would appreciate help. Thanks.

preguntado el 27 de agosto de 12 a las 01:08

Can you provide the output that you Fuck Cancer. getting to add to the explanation of why it's not what you expect? Also, in your example, the prefix variable is not being changed. Is there additional code that has not been provided in your original example? -

I hope your just writing a Select statement like that for troubleshooting -

I don't see prefix variable being changed , or a spot in the while loop to check to see if it was changed , it is just going to execute reader with the variable assigned when it started reading -

The most likely cause is two records in the database with the same NAMESPACE_PREFIX -

Sorry should have mentioned, yes the prefix is being changed in another part of the code. I left it out to make it easier to read. But the first Response.Write is outputting the correctly modified 'prefix.' -

1 Respuestas

The most likely cause is two records in the database with the same NAMESPACE_PREFIX.

Maybe you need a unique index on that field.

Respondido 27 ago 12, 05:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.