Пример #1
0
        private static void UpdateDataAdapter()
        {
            Insert();

            #region Config DataAdapater

            var comm = new DbCommandUtil("SELECT * FROM TEST");

            const string insertSql = "INSERT INTO TEST(ID,VALUE) VALUES(@ID, @VALUES)";
            comm.ChangeDataAdaterCommand(DataAdapterCommand.Insert, insertSql);
            comm.CreateParameter("@ID", DbType.Int32, "ID");
            comm.CreateParameter("@VALUE", DbType.Decimal, 4, 2, "VALUE");

            const string updateSql = "UPDATE TEST SET VALUE = @VALUE) WHERE ID=@ID";
            comm.ChangeDataAdaterCommand(DataAdapterCommand.Update, updateSql);
            comm.CreateParameter("@ID", DbType.Int32, "ID");
            comm.CreateParameter("@VALUE", DbType.Decimal, 4, 2, "VALUE");

            const string deleteSql = "DELETE TEST WHERE ID=@ID";
            comm.ChangeDataAdaterCommand(DataAdapterCommand.Delete, deleteSql);
            comm.CreateParameter("@ID", DbType.Int32, "ID");

            #endregion Config DataAdapater

            var dt = comm.GetDataTable();
            dt.Rows.Add(3, 100.1);
            dt.Rows[0].Delete();
            dt.Rows[1]["VALUE"] = 100.2;
            comm.Update(dt);

            dt = comm.GetDataTable();
            Assert.Equal(2, dt.Rows.Count);
            Assert.Equal(2, dt.Rows[0][0]);
            Assert.Equal(100.2, dt.Rows[0][1]);
            Assert.Equal(3, dt.Rows[1][0]);
            Assert.Equal(100.1, dt.Rows[1][1]);
        }