C# no results unlike workbench
Posted by: Sa'Ed A'Rafat
Date: March 10, 2016 11:55PM

Hi All,

When i run the following SPROC from workbench 6.3 CE i get my expected results however my C# code always reruns empty. I tried different ways to pass in datetime values without success. please help!

SPROC:
CREATE DEFINER=`sa`@`%` PROCEDURE `HistorySearch`(
IN BeginTime datetime,
IN EndTime datetime
)
BEGIN

set @qry = CONCAT('select distinct ID from History where TimeStamp >= ','''',@BeginTime,'''',' and TimeStamp <= ','''',@EndTime,'''');

PREPARE stmt1 FROM @qry;

EXECUTE stmt1;

DEALLOCATE PREPARE stmt1;
END


If I execute this SPROC from workbech as:

set @BeginTime = '2015-03-03 22:42:51';
set @EndTime = '2017-03-03 22:42:51';
call DB1.HistorySearch(@BeginTime, @EndTime);
SELECT @BeginTime, @EndTime;

I get good results.

However i get no results from C#:

try
{
if (_mySqlConnection != null)
{
var cmd = new MySqlCommand
{
Connection = _mySqlConnection,
CommandText = spHistorySearch,
CommandType = CommandType.StoredProcedure
};

cmd.Parameters.AddWithValue("@BeginTime", "2015-03-03 22:42:51");
cmd.Parameters.AddWithValue("@EndTime", "2017-03-03 22:42:51");

MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
rdr.Close();
}
}
catch (MySqlException ex)
{
;
}

I'm using connector Net 6.9.8.

Thank you,
Sa'Ed

Options: ReplyQuote


Subject
Written By
Posted
C# no results unlike workbench
March 10, 2016 11:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.