Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code for accessing the SQLDataReader object looks correct.</p> <p>If I understand you properly, this <code>while</code> loop is not being run:</p> <pre><code> //Empiezo el ciclo while (usuarioDR.Read()) { MessageBox.Show("Paso por aca 2"); // &lt;- It does not execute if (usuarioDR["fechahora"].ToString() != "") { MessageBox.Show("Paso por aca 3"); tipo = (DateTime)usuarioDR["fechahora"]; MessageBox.Show(tipo.ToString()); } else { validar = true; MessageBox.Show("Paso por aca 1"); } } </code></pre> <p>If this loop is not being run, it is because the <code>usuarioDR.Read()</code> function is returning a value of <code>false</code>. Here's some things to try and figure out what is going wrong:</p> <p>Start debugging your code - a good first step would be to put a breakpoint at <code>while (usuarioDR.Read())</code> and see what information is contained in the <code>usuarioDR</code> object at that point in your function. Is there anything in the <code>usuarioDR</code> object? If there isn't, that means nothing is being pushed into <code>usarioDR</code> when you call <code>ExecuteReader()</code>.</p> <p>Try approaching this from the other end - write out your <code>"SELECT TOP 1 * FROM movimiento_docente WHERE (ID = @cedula) ORDER BY id_movimiento DESC"</code> query in the Server Management Studio with a test value for <code>@cedula</code>. Does it generate the results you expect? If it does, then that means that your issue lies within your code and how it accesses the database.</p> <p>In the end, I think it's going to come down to the standard debugging process: Set up breakpoints, step through your code, and check the data in your objects to see if it meets your expectations. </p> <p>One place to start looking might be at your <code>usarioDR</code> object. You start by initializing it as <code>null</code>; is it still <code>null</code> after you run the line <code>usuarioDR = usuario.ExecuteReader();</code>? If it is, that might help you narrow your search. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload