-1
I’m making a SELECT
mysql with inner join
within my application C#
MySqlCommand _comandoDados = new MySqlCommand(String.Format(
"select EMGroot.id, EMGroot.lbs_net, EMGroot.lbs_gross_aai, EMGroot.price_brazil, sum(AAIest.qtd_venda) " +
"from eaglemo4_eaglemotorsg.tb_products_root EMGroot " +
"inner join eaglemo4_americai.tb_estoque AAIest " +
"on AAIest.id_produto = EMGroot.id " +
"where EMGroot.manupart = '" + txtManuPartInserir.Text + "'"), conexao_aai);
MySqlDataReader Open_readerteste = _comandoDados.ExecuteReader();
Open_readerteste.Read();
After getting a Reader I should throw the dice to some fields, but in order to avoid "DATA IS NULL" error, I create the condition HasRows :
if(Open_readerteste.HasRows)
{
root_id = Open_readerteste.GetInt16(0)
....
}
but the result of the condition is always being TRUE
even when there is no
rows
.
Can anyone tell if because of inner join
the reader
always consider data in the ? command or why Hasrows is always true ?
=================
Updating my doubt; Descrobri that in fact the HasRows
is always true
because of the field search sum(AAIest.qtd_venda)
. With the sum() tool Hasrows will always indicate that there are lines within the dataReader.
Is there any way to work this ?
if multiple lines...
while (Open_readerteste.Read())
if it is aif (Open_readerteste.Read())
– Rovann Linhalis
There is a similar question in Soen, in summary one of the answers suggests the use of
MySqlCommand.ExecuteScalar
.– Tuxpilgrim
There are several lines, the Reader I already opened as the code shows (Open_readerteste.Read();).. works perfectly when select finds data, but when it does not find that is where it should NOT enter the 'hasrows' condition it is entering and thus indicating date is null error.
– Maurício Sanches
I found that the problem is in the search for the "sum(Aaiest.qtd_sell)" field using SUM() Hasrows will always inform that there is a line within the Reset dataset. If anyone knows how to fix this !?
– Maurício Sanches