2010-05-27 38 views
0

我想實現這個標籤雲: http://thetagcloud.codeplex.com/Asp.net詞典 - 與數據庫替換硬編碼值的值

...我需要與那些來替換下面的硬編碼值我數據庫?

<%= 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}" 
        }) %> 

我創建返回格式期望的字符串/ int或值的數據

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

你可以發佈你的數據訪問代碼? – Oded 2010-05-27 14:14:56

+0

我認爲您需要修改您的查詢,以便它返回與標籤相關的標識(58,45,36,24,13)以及標籤名稱和計數。 – 2010-05-27 14:20:35

+0

嗨,我在下面添加了我的數據訪問代碼。 謝謝 – Melt 2010-05-27 19:22:55

回答

0

這裏是我的數據訪問代碼

// 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); 
    } 
0

嗯,我有一個超級簡要如下SQL字符串/關鍵看,只是看看示例代碼。我懷疑你需要傳遞一個數組(值對)而不是一個字符串。

只是遍歷每個返回的記錄並將其添加到數組。然後將該數組傳遞給TagCloud對象。