mardi 3 novembre 2015

how to check if a datareader is null or empty - Error

I am using Sqlite as a back End and Windows Form Application (C#) as a front end,

I am going through this code

cmdgetTransaction_ID = new SQLiteCommand("SELECT MAX(transaction_id) as expr1  FROM  transaction_master WHERE transaction_id LIKE '"+temp+"%' ", con);
            SQLiteDataReader reader = cmdgetTransaction_ID.ExecuteReader();
            if (reader["expr1"]!=DBNull.Value)
            {
                name= reader.GetString(0);
                string[] substrings = System.Text.RegularExpressions.Regex.Split(name, "([a-z]+)|([0-9]+)");
                MessageBox.Show(substrings[0]);
            }
            else
            {
                name=name+temp+"1";
                lblTranID.Text = name;

            }`enter code here`

I have also tried with this---- if (reader.IsDBNull(0))

While debugging (step into) it reports following Exception : A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.SQLite.dll

I can not figure it out what mistake i am doing , so that i generates an exception

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire