예제 #1
0
        /// <summary>
        /// Finds a Testsqlentity entity using it's primary key.
        /// </summary>
        /// <param name="sqlstringcolumn">A key field.</param>
        /// <param name="sqlintcolumn">A key field.</param>
        /// <returns>A TestsqlentityData object.</returns>
        /// <exception cref="Spring2.Core.DAO.FinderException">Thrown when no entity exists witht he specified primary key..</exception>
        public static TestsqlentityData Load(StringType stringColumn, IdType int32Column)
        {
            WhereClause w = new WhereClause();

            w.And("sqlstringcolumn", stringColumn.DBValue);
            w.And("sqlintcolumn", int32Column.DBValue);
            SqlDataReader dataReader = GetListReader(CONNECTION_STRING_KEY, VIEW, w, null);

            if (!dataReader.Read())
            {
                dataReader.Close();
                throw new FinderException("Load found no rows for Testsqlentity.");
            }
            TestsqlentityData data = GetDataObjectFromReader(dataReader);

            dataReader.Close();
            return(data);
        }
예제 #2
0
        /// <summary>
        /// Returns an object which matches the values for the fields specified.
        /// </summary>
        /// <param name="sqlstringcolumn">A field value to be matched.</param>
        /// <param name="sqlintcolumn">A field value to be matched.</param>
        /// <returns>The object found.</returns>
        /// <exception cref="Spring2.Core.DAO.FinderException">Thrown when no rows are found.</exception>
        public static TestsqlentityData FindByPK(StringType stringColumn, IdType int32Column)
        {
            OrderByClause sort   = new OrderByClause("sqlstringcolumn, sqlintcolumn");
            WhereClause   filter = new WhereClause();

            filter.And("sqlstringcolumn", stringColumn.DBValue);
            filter.And("sqlintcolumn", int32Column.DBValue);
            SqlDataReader dataReader = GetListReader(CONNECTION_STRING_KEY, VIEW, filter, sort);

            if (!dataReader.Read())
            {
                dataReader.Close();
                throw new FinderException("TestsqlentityData.FindByPK found no rows.");
            }
            TestsqlentityData data = GetDataObjectFromReader(dataReader);

            dataReader.Close();
            return(data);
        }
예제 #3
0
        /// <summary>
        /// Updates a record in the Testsqlentity table.
        /// </summary>
        /// <param name=""></param>
        public static void Update(TestsqlentityData data, SqlTransaction transaction)
        {
            // Create and execute the command
            SqlCommand cmd = GetSqlCommand(CONNECTION_STRING_KEY, "spTestsqlentity_Update", CommandType.StoredProcedure, COMMAND_TIMEOUT, transaction);

            //Create the parameters and append them to the command object
            cmd.Parameters.Add(new SqlParameter("@sqlstringcolumn", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "StringColumn", DataRowVersion.Proposed, data.StringColumn.DBValue));
            cmd.Parameters.Add(new SqlParameter("@sqlintcolumn", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "Int32Column", DataRowVersion.Proposed, data.Int32Column.DBValue));
            cmd.Parameters.Add(new SqlParameter("@EmailFormat", SqlDbType.Char, 1, ParameterDirection.Input, false, 0, 0, "EmailFormat", DataRowVersion.Proposed, data.EmailFormat.DBValue));
            cmd.Parameters.Add(new SqlParameter("@addr1", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Address.Address1", DataRowVersion.Proposed, data.Address.Address1.DBValue));
            cmd.Parameters.Add(new SqlParameter("@addr2", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Address.Address2", DataRowVersion.Proposed, data.Address.Address2.DBValue));
            cmd.Parameters.Add(new SqlParameter("@city", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Address.City", DataRowVersion.Proposed, data.Address.City.DBValue));
            cmd.Parameters.Add(new SqlParameter("@state", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Address.State", DataRowVersion.Proposed, data.Address.State.DBValue));
            cmd.Parameters.Add(new SqlParameter("@zip", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Address.PostalCode", DataRowVersion.Proposed, data.Address.PostalCode.DBValue));

            // Execute the query
            cmd.ExecuteNonQuery();

            // do not close the connection if it is part of a transaction
            if (transaction == null)
            {
                cmd.Connection.Close();
            }
        }
예제 #4
0
 /// <summary>
 /// Updates a record in the Testsqlentity table.
 /// </summary>
 /// <param name=""></param>
 public static void Update(TestsqlentityData data)
 {
     Update(data, null);
 }
예제 #5
0
 /// <summary>
 /// Inserts a record into the Testsqlentity table.
 /// </summary>
 /// <param name=""></param>
 public static void Insert(TestsqlentityData data)
 {
     Insert(data, null);
 }
예제 #6
0
        /// <summary>
        /// Builds a data object from the current row in a data reader..
        /// </summary>
        /// <param name="dataReader">Container for database row.</param>
        /// <returns>Data object built from current row.</returns>
        private static TestsqlentityData GetDataObjectFromReader(SqlDataReader dataReader)
        {
            TestsqlentityData data = new TestsqlentityData();

            if (dataReader.IsDBNull(dataReader.GetOrdinal("sqlstringcolumn")))
            {
                data.StringColumn = StringType.UNSET;
            }
            else
            {
                data.StringColumn = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("sqlstringcolumn")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("sqlintcolumn")))
            {
                data.Int32Column = IdType.UNSET;
            }
            else
            {
                data.Int32Column = new IdType(dataReader.GetInt32(dataReader.GetOrdinal("sqlintcolumn")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("EmailFormat")))
            {
                data.EmailFormat = FormatType.UNSET;
            }
            else
            {
                data.EmailFormat = FormatType.GetInstance(dataReader.GetString(dataReader.GetOrdinal("EmailFormat")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("addr1")))
            {
                data.Address.Address1 = StringType.UNSET;
            }
            else
            {
                data.Address.Address1 = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("addr1")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("addr2")))
            {
                data.Address.Address2 = StringType.UNSET;
            }
            else
            {
                data.Address.Address2 = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("addr2")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("city")))
            {
                data.Address.City = StringType.UNSET;
            }
            else
            {
                data.Address.City = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("city")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("state")))
            {
                data.Address.State = StringType.UNSET;
            }
            else
            {
                data.Address.State = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("state")));
            }
            if (dataReader.IsDBNull(dataReader.GetOrdinal("zip")))
            {
                data.Address.PostalCode = StringType.UNSET;
            }
            else
            {
                data.Address.PostalCode = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("zip")));
            }

            return(data);
        }