3
I’m having trouble reading the values returned from a select
, on the line where I do:
OracleDataReader reader = cmd.ExecuteReader();
in the read
it brings me the values correctly, but in the next line where I do reader.Read()
says that the enumeration did not produce results.
How do I solve this problem?
Source
OracleConnection cnn = new OracleConnection(DataFunctions.GetDefaultConnectionString()); OracleCommand cmd = cnn.CreateCommand(); OracleDataAdapter adapter = new OracleDataAdapter();
try
{
cnn.Open();
cmd.Connection = cnn;
cmd.CommandText = String.Format("select * from VI_TESTE where cd_codigo = {0}", code);
OracleDataReader reader = cmd.ExecuteReader();
// Ao debugar, aqui tem registros
if (reader.Read())
{
// aqui não tem mais registros
var test1 = reader.GetValue(0);
}
}
finally
{
cnn.Close();
}
Have a record only or more? When you debug, you can see even the selected values?
– Leonel Sanches da Silva
If you check
if(reader.HasRows)
, he returnstrue
?– Marcus Vinicius
@Gypsy Morrison Mendez, It has only one record with 5 fields, in the case cd_codigo is the table PK.
– filipe_21
@Marcusvinicius yes it returns true in if(Remailer.Hasrows)
– filipe_21
@filipe_21 I find it inappropriate
reader
for your case. I will put an answer.– Leonel Sanches da Silva
Have you tested without being in debug? I found a similar question on Soen: http://stackoverflow.com/questions/6493955/datareader-has-rows-and-data-trying-to-read-from-it-says-no-data-is-present, apparently using debug causes Datareader to list and not return results when the code arrives on
reader.GetValue(0);
– Marcus Vinicius
@Marcusvinicius I think when he inspects the variable already occurs the iteration on top of the enumeration. So the enumeration enters empty inside the
if
.– Leonel Sanches da Silva
@Gypsy omorrisonmendez Exactly what I thought, let’s wait for his answer.
– Marcus Vinicius