Beispiel #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();
                    }
                }
            }
        }