views:

118

answers:

1

When I use the first item in a zero-based Enum cast to Int32 as a query parameter, the parameter value is null. I've worked around it by simply setting the first item to a value of 1, but I was wondering though what's really going on here? This one has me scratching my head. Why is the parameter value regarded as null, instead of 0?

Enum LogEventType : int
{
    SignIn,
    SignInFailure,
    SignOut,
    ...
}

private static DataTable QueryEventLogSession(DateTime start, DateTime stop)
{
    DataTable entries = new DataTable();

    using (FbConnection conn = new FbConnection(DSN))
    {
        using (FbDataAdapter adapter = new FbDataAdapter(
            "SELECT event_type, event_timestamp, event_details FROM event_log " +
            "WHERE event_timestamp BETWEEN @start AND @stop " +
            "AND event_type IN (@signIn, @signInFailure, @signOut) " +
            "ORDER BY event_timestamp ASC", conn))
        {
            adapter.SelectCommand.Parameters.AddRange(new Object[] {
                new FbParameter("@start", start),
                new FbParameter("@stop", stop),
                new FbParameter("@signIn", (Int32)LogEventType.SignIn),
                new FbParameter("@signInFailure", (Int32)LogEventType.SignInFailure),
                new FbParameter("@signOut", (Int32)LogEventType.SignOut)});

            Trace.WriteLine(adapter.SelectCommand.CommandText);
            foreach (FbParameter p in adapter.SelectCommand.Parameters)
            {
                Trace.WriteLine(p.Value.ToString());
            }

            adapter.Fill(entries);
        }
    }
    return entries;
}
+1  A: 

I do not know this api but it may be a bug. Try passing in a FbDbType enum when defining the params.

http://www.firebirdsql.org/dotnetfirebird/documentation/api/1.7/FirebirdSql.Data.Firebird.FbDbType.html

http://www.firebirdsql.org/dotnetfirebird/documentation/api/1.7/FirebirdSql.Data.Firebird.FbParameter.html

Another option is to try adding the parameters one by one instead of using an object array and the AddRange method.

Raj Kaimal
Thank you for your help and your answer. `adapter.SelectCommand.Parameters.Add("@signIn", FbDbType.Integer).Value = (Int32)LoggerEventType.SignIn;` works as intended. I agree, it must be a bug.
Timothy