c# insert statement from class

public class Insert
{
    Hashtable args = new Hashtable();
    string table;

    /// <summary>
    /// Constructs Insert object
    /// </summary>
    /// <param name="table">table name to insert to</param>
    public Insert(string table)
    {
        this.table = table;
    }

    /// <summary>
    /// Adds item to Insert object
    /// </summary>
    /// <param name="name">item name</param>
    /// <param name="val">item value</param>
    public void Add(string name, object val)
    {
        args.Add(name, val);
    }

    /// <summary>
    /// Removes item from Insert object
    /// </summary>
    /// <param name="name">item name</param>
    public void Remove(string name)
    {
        try
        {
            args.Remove(name);
        }
        catch
        {
            throw (new Exception("No such item"));
        }
    }

    /// <summary>
    /// Test representatnion of the Insert object (SQL query)
    /// </summary>
    /// <returns>System.String</returns>
    public override string ToString()
    {
        StringBuilder s1 = new StringBuilder();
        StringBuilder s2 = new StringBuilder();

        IDictionaryEnumerator enumInterface = args.GetEnumerator();
        bool first = true;
        while(enumInterface.MoveNext())
        {
            if (first) first = false;
            else
            {
                s1.Append(", ");
                s2.Append(", ");
            }
            s1.Append(enumInterface.Key.ToString());
            s2.Append(enumInterface.Value.ToString());
        }

        return "INSERT INTO " + table + " (" + s1 + ") VALUES (" + s2 + ");";
    }

    /// <summary>
    /// Gets or sets item into Insert object
    /// </summary>
    object this[string key]
    {
        get
        {
            Debug.Assert(args.Contains(key), "Key not found");
            return args[key];
        }
        set {args[key]=value;}
    }
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source