Exemplo n.º 1
0
        private Entities.Data GetDataRecord(string key)
        {
            SqlCommand command = new SqlCommand("SELECT TOP 1 * FROM DbM_Data WHERE [Key] = @Key");

            command.Parameters.Add(
                new SqlParameter("Key", key)
            {
                SqlDbType = System.Data.SqlDbType.VarChar, Size = 100
            });

            Entities.Data item = null;

            using (var connection = NewConnection())
            {
                connection.Open();
                command.Connection = connection;
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    item = ParseData(reader);
                }
                reader.Close();
                connection.Close();
            }

            return(item);
        }
Exemplo n.º 2
0
        private Entities.Data ParseData(SqlDataReader reader)
        {
            var item = new Entities.Data()
            {
                Id    = (int)reader["Id"],
                Value = (string)reader["Value"],
                Key   = (string)reader["Key"]
            };

            return(item);
        }
Exemplo n.º 3
0
        private SqlCommand GetDataUpdateByKeyQueryCommand(Entities.Data data)
        {
            string     query   = @"UPDATE [dbo].[DbM_Data] SET
    [Value] = @Value
WHERE [Key] = @Key;
";
            SqlCommand command = new SqlCommand(query);

            command.Parameters.Add(new SqlParameter("Key", data.Key)
            {
                SqlDbType = System.Data.SqlDbType.VarChar, Size = 50
            });
            command.Parameters.Add(new SqlParameter("Value", data.Value)
            {
                SqlDbType = System.Data.SqlDbType.VarChar, Size = 255
            });

            return(command);
        }
Exemplo n.º 4
0
        private MySqlCommand GetDataUpdateByKeyQueryCommand(Entities.Data data)
        {
            string       query   = @"UPDATE DbM_Data SET
    `Value` = @Value
WHERE `Key` = @Key;
";
            MySqlCommand command = new MySqlCommand(query);

            command.Parameters.Add(new MySqlParameter("Key", data.Key)
            {
                MySqlDbType = MySqlDbType.VarChar, Size = 50
            });
            command.Parameters.Add(new MySqlParameter("Value", data.Value)
            {
                MySqlDbType = MySqlDbType.VarChar, Size = 255
            });

            return(command);
        }
Exemplo n.º 5
0
        private SqlCommand GetDataInsertQueryCommand(Entities.Data data)
        {
            string     query   = @"INSERT INTO [dbo].[DbM_Data]
    ([Key] 
    ,[Value])
VALUES
    (@Key
    ,@Value);
";
            SqlCommand command = new SqlCommand(query);

            command.Parameters.Add(new SqlParameter("Key", data.Key)
            {
                SqlDbType = System.Data.SqlDbType.VarChar, Size = 100
            });
            command.Parameters.Add(new SqlParameter("Value", data.Value)
            {
                SqlDbType = System.Data.SqlDbType.VarChar, Size = 255
            });

            return(command);
        }
Exemplo n.º 6
0
        private MySqlCommand GetDataInsertQueryCommand(Entities.Data data)
        {
            string       query   = @"INSERT INTO DbM_Data
    (`Key` 
    ,`Value`)
VALUES
    (@Key
    ,@Value);
";
            MySqlCommand command = new MySqlCommand(query);

            command.Parameters.Add(new MySqlParameter("Key", data.Key)
            {
                MySqlDbType = MySqlDbType.VarChar, Size = 100
            });
            command.Parameters.Add(new MySqlParameter("Value", data.Value)
            {
                MySqlDbType = MySqlDbType.VarChar, Size = 255
            });

            return(command);
        }