Пример #1
0
        public void DataAdapterUpdateReturnValue2()
        {
            var cmd = TheConnection.CreateCommand();
            var da  = new NpgsqlDataAdapter("select * from tabled", TheConnection);
            var cb  = new NpgsqlCommandBuilder(da);
            var ds  = new DataSet();

            da.Fill(ds);

            //## Insert a new row with id = 1
            ds.Tables[0].Rows.Add(new Object[] { 0.4, 0.5 });
            da.Update(ds);

            //## change id from 1 to 2
            cmd.CommandText = "update tabled set field_float4 = 0.8 where id = (select max(field_serial) from tabled)";
            cmd.ExecuteNonQuery();

            //## change value to newvalue
            ds.Tables[0].Rows[0][1] = 0.7;
            //## update should fail, and make a DBConcurrencyException
            var count = da.Update(ds);

            //## count is 1, even if the isn't updated in the database
            Assert.AreEqual(0, count);
        }
Пример #2
0
        public void CleansupOkWithDisposeCalls()
        {
            NpgsqlCommand command = new NpgsqlCommand("select * from tablea", TheConnection);

            using (NpgsqlDataReader dr = command.ExecuteReader())
            {
                dr.Read();

                dr.Close();
                using (NpgsqlCommand upd = TheConnection.CreateCommand())
                {
                    upd.CommandText = "select * from tablea";
                    upd.Prepare();
                }
            }
        }