Subclass which contains all of an individual row's columns as individual DatabaseItem objects
Exemplo n.º 1
0
        /// <summary>
        /// Instantiate the class with a Halide.H3DataRowConfig class variable
        /// to specify what should be loaded, and from where. You must
        /// specify either 1) a SQL Command, or 2) a Table Name, Primary Key Name
        /// and Primary Key Value. SQL command overrides all other parameters.
        /// </summary>
        /// <example>
        /// <code>
        /// using Argentini.Halide;
        /// ...
        /// H3DataRowConfig dataCon = new H3DataRowConfig();
        /// dataCon.ConnectionName = "MyConnection";
        /// dataCon.TableName = "News";
        /// dataCon.PrimarykeyName = "News_ID";
        /// dataCon.PrimaryKeyValue = "15";
        /// H3DataRow data = new H3DataRow(dataCon);
        /// </code>
        /// </example>
        /// <param name="DataCon">Halide.H3DataRowConfig object with database settings.</param>
        public H3DataRow(H3DataRowConfig DataCon)
        {
            String SqlCmd = "";
            DataPresent = false;

            ConnectionStringName = DataCon.ConnectionName;

            // If DataCon has a SQL command passed...
            if (!String.IsNullOrEmpty(DataCon.SqlCommand))
            {
                SqlCmd = DataCon.SqlCommand;
            }

            else
            {
                // If DataCon object has table name, primary key name and value passed...
                if (!String.IsNullOrEmpty(DataCon.PrimarykeyName) && !String.IsNullOrEmpty(DataCon.PrimaryKeyValue) && !String.IsNullOrEmpty(DataCon.TableName))
                {
                    SqlCmd = "SELECT TOP 1 * FROM " + DataCon.TableName + " WHERE " + DataCon.PrimarykeyName + "='" + DataCon.PrimaryKeyValue.Replace("'", "''") + "'";
                }

                else
                {
                    // If DataCon object has table name and primary key value passed...
                    if (!String.IsNullOrEmpty(DataCon.PrimaryKeyValue) && !String.IsNullOrEmpty(DataCon.TableName))
                    {
                        using (Halide.H3Reader reader = new Halide.H3Reader("SELECT TOP 1 * FROM " + DataCon.TableName, true, ConnectionStringName))
                        {
                            reader.Read();
                            String PrimaryKey = reader.GetPrimarykeyName();
                            SqlCmd = "SELECT TOP 1 * FROM " + DataCon.TableName + " WHERE " + PrimaryKey + "='" + DataCon.PrimaryKeyValue.Replace("'", "''") + "'";
                        }
                    }

                    // If all else fails, load an empty object
                    else
                    {
                        Column = new DatabaseRow();
                    }
                }
            }

            // Instantiate the data object if valid parameters have been passed
            if (!String.IsNullOrEmpty(SqlCmd))
            {
                using (Halide.H3Reader reader = new Halide.H3Reader(SqlCmd, true, DataCon.ConnectionName))
                {
                    if (reader.HasRows)
                    {
                        DataPresent = true;
                        reader.Read();
                        Column = new DatabaseRow(reader);
                    }

                    else
                    {
                        Column = new DatabaseRow();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instantiate the class with a complete SQL statement.
        /// </summary>
        /// <example>
        /// <code>
        /// using Argentini.Halide;
        /// ...
        /// H3DataRow dataRow = new H3DataRow("SELECT TOP 1 * FROM Data WHERE ID=5;", "SqlServer01");
        /// </code>
        /// </example>
        /// <param name="sqlCommand">Complete SQL command string to use for reading the desired row.</param>
        /// <param name="UseconnectionStringName">Name of a connection string within the Web.config file.</param>
        public H3DataRow(String sqlCommand, String UseconnectionStringName)
        {
            ConnectionStringName = UseconnectionStringName;
            DataPresent = false;

            using (H3Reader reader = new H3Reader(sqlCommand, true, UseconnectionStringName))
            {
                if (reader.HasRows)
                {
                    DataPresent = true;
                    reader.Read();
                    Column = new DatabaseRow(reader);
                }

                else
                {
                    Column = new DatabaseRow();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Instantiate the class with a connection string name.
 /// This method is primarily for inserting new objects into a database.
 /// </summary>
 /// <example>
 /// <code>
 /// using Argentini.Halide;
 /// ...
 /// H3DataRow dataRow = new H3DataRow("SqlConnection");
 /// </code>
 /// </example>
 /// <param name="connectionStringName">A connection string name.</param>
 public H3DataRow(String connectionStringName)
 {
     DataPresent = false;
     ConnectionStringName = connectionStringName;
     Column = new DatabaseRow();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Instantiate the class with a Control object reference.
 /// This is used to read in a group of controls and their values from
 /// within the parent control. If using the "Exec()" method, this allows
 /// the developer to easily save a submitted form to a database without
 /// having to manually process and pass the stord procedure parameters.
 /// Uses the default connection string "Halide".
 /// </summary>
 /// <example>
 /// <code>
 /// using Argentini.Halide;
 /// ...
 /// H3DataRow dataRow = new H3DataRow(form1);
 /// ...
 /// dataRow.Exec("spu_SaveRecord");
 /// </code>
 /// </example>
 /// <param name="containerControl">Control object with submitted form data.</param>
 public H3DataRow(Control containerControl)
 {
     DataPresent = true;
     ConnectionStringName = "Halide";
     Column = new DatabaseRow();
     LoadForm(containerControl);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Instantiate the class with an open H3Reader object.
        /// </summary>
        /// <example>
        /// <code>
        /// using Argentini.Halide;
        /// ...
        /// H3Reader reader = new H3Reader("SELECT TOP 1 * FROM Data WHERE ID=5;", "SqlServer01");
        /// reader.Read()
        /// H3DataRow dataRow = new H3DataRow(reader);
        /// reader.Close();
        /// </code>
        /// </example>
        /// <param name="reader">Halide.H3Reader object, opened and read().</param>
        public H3DataRow(Halide.H3Reader reader)
        {
            DataPresent = false;

            if (reader.HasRows)
            {
                DataPresent = true;
                ConnectionStringName = reader.connectionStringName;
                Column = new DatabaseRow(reader);
            }

            else
            {
                Column = new DatabaseRow();
            }
        }