开发者

Asp.net Dictionary - Replace hard coded values with database values

开发者 https://www.devze.com 2023-01-01 01:40 出处:网络
I\'m trying to implement this tag cloud: http://thetagcloud.codeplex.com/ ...and I need the replace the hard-coded values below with those coming from my database?

I'm trying to implement this tag cloud: http://thetagcloud.codeplex.com/

...and I need the replace the hard-coded values below with those coming from my database?

    <%= new TagCloud(   new Dictionary<string, int> {
                        {"C#", 58},
                        {"ASP.NET", 45},
                        {"VB.NET", 36},
    开发者_如何学运维                    {"AJAX", 24},
                        {"LINQ", 13}
                    },
                    new TagCloudGenerationRules
                    {
                        TagToolTipFormatString = "Tag weight: {0}",
                        TagUrlFormatString = "search.aspx?p=1&tag={0}"
                    }) %>

I've created the following sql string which returns the data in the format expected string/int or value/key

SELECT Tag, COUNT(Tag) AS Counter
FROM         dbo.CtagCloud
GROUP BY Tag
HAVING      (COUNT(Tag) > 3)
ORDER BY Counter DESC


here's my data access code

 // SQL Select Command
    SqlConnection conn = new SqlConnection(connectionString);
    SqlCommand mySqlSelect = new SqlCommand("SELECT TOP (100) PERCENT Tag, COUNT(Tag) AS Counter FROM dbo.CtagCloud GROUP BY Tag HAVING (COUNT(Tag) > 3) ORDER BY Counter DESC", conn);
    mySqlSelect.CommandType = CommandType.Text;
    SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
    DataSet myDataSet = new DataSet();
    mySqlAdapter.Fill(myDataSet);

    // create an instance for ArrayList
    ArrayList myArrayList = new ArrayList();

    // foreach loop to read each DataRow of DataTable stored inside the DataSet
    foreach (DataRow dRow in myDataSet.Tables[0].Rows)
    {
        // add DataRow object to ArrayList
        myArrayList.Add(dRow);
    }


Hmm, I've had a super brief look, just glazing over that sample code. I suspect you need to pass in an Array (value pairs) not a string.

Just loop through each records returned and add it to an array. Then pass that array into the TagCloud object.

0

精彩评论

暂无评论...
验证码 换一张
取 消