> agent_id = dr.GetInt32(0);
Change to:
if (!dr.IsDBNull(0))
agent_id = dr.GetInt32(0);
else
agent_id = -1;
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Gelios" <gelios@rbcmail.ru> wrote in message news:d4urr2$2b3c$1@gavrilo.mtu.ru...[color=blue]
>I had thought and decide to manually catch exception, but exception is System.Data.SqlTypes.SqlNullValueException.
> But this type of exception is generated only in case of using SQL Server, but i need some abstract exception to catch
> from all database types. Does somebody has any ideas how can i do it?
>
>
> Gelios wrote:[color=green]
>> Hello All!
>> I am going to crazy and feeling myself so stupid but I don't understand such behaviour.
>> I have code:
>> public int getNextAgentId()
>> {
>> Int32 agent_id = 0;
>> IDataReader dr = dbap.DBDataReader("SELECT MAX(agent_id) FROM Agents");
>> if(dr.Read())
>> {
>> agent_id = dr.GetInt32(0);
>> }
>> dr.Close();
>> return agent_id + 1;
>> }
>>
>> where dpab is an instance of DB abstraction class, hence using IDataReader interface instead of
>> concrete DB DataReader such as SqlDataReader.
>>
>> SELECT returns null due to database table is empty and I have
>> error message "Data is Null. This method or property cannot be called on Null values."
>> on line agent_id = dr.GetInt32(0);
>> As I understand in the begining datareader positioned before first reacord and when I call Read method
>> it should point to first record but why it returns true in conditions when now rows returned from DB?
>>
>> Any ideas?
>> Thanks in advance to all.
>>
>> Regards,
>> Nodir Gulyamov[/color][/color]