Пример #1
0
        public void NullParameterTest()
        {
            Insert();
            var comm = new DbCommandUtil("SELECT * FROM TEST WHERE ID = @ID");

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            comm.AddParameter("@ID", DbType.Int32, null);
            Assert.Equal(0, comm.GetDataTable().Rows.Count);
            comm.SetParameterValue("@ID", 0);
            Assert.Equal(0, comm.GetDataTable().Rows.Count);
        }
Пример #2
0
        public void BasicDbCommandUtilTest()
        {
            // Select
            var comm = new DbCommandUtil("SELECT * FROM TEST");

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            var dataTable = comm.GetDataTable();

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            Assert.Equal(2, dataTable.Columns.Count);
            Assert.Equal("ID", dataTable.Columns[0].ColumnName);
        }
Пример #3
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]);
        }
Пример #4
0
        public void DataTableTest()
        {
            // DataTable
            Insert();
            var comm = new DbCommandUtil("SELECT * FROM TEST");

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            var dataTable = comm.GetDataTable();

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            Assert.Equal(2, dataTable.Columns.Count);
            Assert.Equal(2, dataTable.Rows.Count);
            Assert.Equal(2, dataTable.Rows[0][0]);
            Assert.Equal(1.2, dataTable.Rows[0][1]);
            Assert.Equal(3, dataTable.Rows[1][0]);
            Assert.Equal(35.4, dataTable.Rows[1][1]);
            Assert.Equal("ID", dataTable.Columns[0].ColumnName);
        }
Пример #5
0
        private void BuildTable()
        {
            string sql = String.Format("SELECT TOP 0 * FROM {0}", FullName);

            using (var comm = new DbCommandUtil(sql))
            {
                _TableSchema           = comm.GetDataTable();
                _TableSchema.TableName = Name;
            }
            // Build columns
            foreach (DataColumn column in _TableSchema.Columns)
            {
                var tableColumn = new Column
                {
                    Name      = column.ColumnName,
                    AllowNull = column.AllowDBNull,
                    ReadOnly  = column.ReadOnly,
                    DataType  = column.DataType,
                    MaxLength = column.MaxLength
                };
                Columns.Add(tableColumn.Name, tableColumn);
            }
            BuildIndexes();
        }