Archive for Ottobre 7th, 2007

Get a string of Shopping cart cookie data

Ottobre 7th, 2007

Description: Returns a string with all the cookies cocatenated together. This can be passed to a business tier to retrieve a table of all shopping cart items.

Link: http://www.codekeep.net/snippets/0e1b66ac-80dd-4c9f-9750-868758b1a243.aspx

protected string GetCartString()
    {
        HttpCookieCollection hc = new HttpCookieCollection();
        hc = Request.Cookies;
        string ItemsQuantity = "";
        foreach (String sc in hc)
        {
            HttpCookie c = hc[sc];
            ItemsQuantity += c.Value.ToString().Trim() + ",";
        }

        //trim end comma
        if (ItemsQuantity.Length > 0)
            ItemsQuantity = ItemsQuantity.Substring(0, ItemsQuantity.Length - 1);

        return ItemsQuantity;
    }

SqlDataReader

Ottobre 7th, 2007

Description: simple SqlDataReader code in a class that returns a SqlDataReader. The connection string is stored in the web.config file

Link: http://www.codekeep.net/snippets/027e44ca-9e6f-488f-bb1a-59b56192f7b7.aspx

        public SqlDataReader GetDivisions(string sqlConn) {
            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[sqlConn]);

            strSQL = "Select * from Divisions Where Status = 'A' order by SortOrder, DIV";
            cn.Open();
            SqlCommand cmd;
            SqlDataReader rdr;
            cmd = new SqlCommand(strSQL, cn);
            rdr = cmd.ExecuteReader();
	    cn.Close()

            return rdr;
        }