RE: Integrating Predictions with Web Applications
RE: Integrating Predictions with Web Applications
Source: http://www.tech−archive.net/Archive/SQL−Server/microsoft.public.sqlserver.datamining/2006−03/msg00006.html
• From: "aa_ecs@xxxxxxxxxxx"
• Date: Wed, 01 Mar 2006 19:40:13 GMT Hi, Thanks so much for your super fast respond. My ASP.NET page is now working correctly. I changed my dmx query to "select flattened predict...".
I don't have the book handy but you might want to set break point at the following line and watch closely..
while (dr.Read()) { string val = dr.GetString(0); RecommenderList.Items.Add(val); } Instead of your above code, could you try the following? In ***asp.net 1.1*** , I have done the following: IDataReader reader = cmd.executereader(); dropdownlist.datasource = reader; dropdownlist.datatextfield = "replaceherewithyourtextcolumn"; dropdownlist.datavaluefield = "replaceherewithidcolumn"; dropdownlist.databind(); You might want to put breakpoints at different places of your code and see actual contents. −− http://zulfiqar.typepad.com BSEE, MCP
"aa_ecs@xxxxxxxxxxx" wrote: RE: Integrating Predictions with Web Applications 1
RE: Integrating Predictions with Web Applications
Hi, I am just wondering how would I be able to integrate the data mining results with ASP.NET page. I followed the book, Data Mining with SQL Server 2005, chapter15, which gives an example how to implement a web cross−selling application. I have set up the role & permission in the Analysis services database. I've also written a code which is embebedded in the ASP.NET page as follow. When I compiled it, VWD did not return me any errors. However, during the execution, when I added a product into the BasketList, an item displayed as "Microsoft.AnalysisServicesAdomdClient.AdomdDataReader" is added into the RecommenderList. When I added another product, another (same) item "Microsoft.AnalysisServicesAdomdClient.AdomdDataReader" is added into the list. I tested my DMX query in the SQL Server Management Studio, it worked fine and gave me expected results. Any ideas where I went wrong?
cheers,
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.AnalysisServices.AdomdClient; public partial class _Default : System.Web.UI.Page { AdomdConnection con; protected void Page_Load(object sender, EventArgs e) { CreateADOMDConnection(); } protected void Add_btn_Click(object sender, EventArgs e) { if (ProductList.SelectedItem != null) { BasketList.Items.Add(new ListItem(ProductList.SelectedItem.Text)); string DMX = GenerateDMX(); ExecuteAndFethSQL(DMX); } } RE: Integrating Predictions with Web Applications 2
RE: Integrating Predictions with Web Applications protected void Remove_btn_Click(object sender, EventArgs e) { if (BasketList.SelectedItem != null) { BasketList.Items.Remove(BasketList.SelectedItem); string DMX = GenerateDMX(); ExecuteAndFethSQL(DMX); } } public bool CreateADOMDConnection() { con = new AdomdConnection("Provider=SQLOLEDB.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Battlemanor"); try { con.Open(); } catch (System.Exception e) { Log(e.Message); return false; } return true; } public string GenerateDMX() { string DMX1 = "select predict(Association_Mining.Products, 5) from Association_Mining natural prediction join (select ("; string DMX2 = ") as Products) as t"; int Count = BasketList.Items.Count; string DMX = ""; for (int i = 0; i < Count; i++) { string ProductName = BasketList.Items[i].Text; DMX += "select '" + ProductName + "' as ProductName "; if (i < Count − 1) { DMX += "union "; } } DMX = DMX1 + DMX + DMX2; return DMX; } public bool ExecuteAndFethSQL(string strCommand) { AdomdCommand cmd = (AdomdCommand)con.CreateCommand(); cmd.CommandText = strCommand; IDataReader dr = null; try RE: Integrating Predictions with Web Applications 3
RE: Integrating Predictions with Web Applications { dr = cmd.ExecuteReader(); } catch (Exception e) { Log(e.Message); return false; } while (dr.Read()) { string val = dr.GetString(0); RecommenderList.Items.Add(val); } return true; } public void Log(string message) { System.Diagnostics.Debug.Assert(false, message); } }
.
RE: Integrating Predictions with Web Applications
4