Developer forum

Forum » Development » StatisticsProvider error: Column '' does not belong to table

StatisticsProvider error: Column '' does not belong to table

Andrey Kozachuk
Reply

Hello,

I am trying to implement my statistics provider following section "STATISTICS PROVIDERS" from this document: http://developer.dynamicweb.com/Files/Filer/Documentation/Development/eCommerce/(en-US)%20eCommerce%20Extensibility%20API,%20%20Dynamicweb%20eCommerce.pdf.

When I add rows to data table I get following error:

"Column '' does not belong to table MyTable." See Attached screenshot.

Following is code of my Statistics provider. If I remove lines that add DataRow to Data table in method CollectData it works without errors but chart is missing.

What am I doing wrong?

[AddInName("OrderTotalCountryStatisticsProvider"), AddInDescription("Order total + country filter"), AddInGroup("Orders"), AddInImage("tree/btn_currency.png")]

public class OrderTotalCountryStatisticsProvider : StatisticsProvider, IDropDownOptions

{

private DataTable _statDataTable = null;

[AddInParameter("CountryDropdown"), AddInParameterEditor(typeof(Dynamicweb.Extensibility.Editors.DropDownParameterEditor), "")]

public string CountryDropDown { get; set; }

public System.Collections.Hashtable GetOptions(string name)

{

Hashtable result = new Hashtable();

foreach (var country in Dynamicweb.eCommerce.Common.Application.Countries)

{

result.Add(country.Code2, country.CountryText.Name);

}

return result;

}

public override string XAxisColumn { get { return "Date"; } }

public override string YAxisColumn { get { return "Orders"; } }

 

public override DataTable Data

{

get

{

if ((_statDataTable == null))

{

_statDataTable = CollectData();

}

return _statDataTable;

}

}

private DataTable CollectData()

{

DataTable ret = new DataTable("MyTable");

ret.Columns.Add("Orders", typeof(int));

ret.Columns.Add("Date", typeof(string));

ret.Columns.Add("Country", typeof(string));

DataRow row = ret.NewRow();

row["Orders"] = 10;

row["Date"] = DateTime.Parse("7-8-2015").Date;

row["Country"] = "DE";

ret.Rows.Add(row);

return ret;

}

}

 

P. S.

The problem was in ColorColunm property - it is a required field to override. I overrided it and added Color column to DataTable. Now everything works

DynamicWebError.png

Replies

 
Dmitrij Jazel
Reply

Hi Andrey,

Just guessing... but in the error message - it says that the Column name (of the talble you are trying to reach) is empty string [''].

Are you sure that the table "MyTable" has the column that you are trying to reach?

/Dmitrij

 
Andrey Kozachuk
Reply

Hi Drimtij,

Table contains columns Orders, Date and Country. In axis methods I am using Date and Orders - they are in the list. In data row - Orders, Date and Country.

I have tried to change data types, but without success.

 
Dmitrij Jazel
Reply

Ok, but what I see in your code, is when you are creating new table in C# CollectData() methodDataTable ret = new DataTable("MyTable");

Than you are adding columns to "ret" table. here you did not do save the table, or anything, So my guess is that table is not created first.Than Next thing you do is creating a row, and adding new values in it.

Just guessing, maybe you are trying to write something that does not exist yet. And since Error message is saying "MyTable" - this means that there is an issue with the way you create that table/or row.

If you compare this example:

http://www.dotnetperls.com/datatable

To what you have in your your implementation in CollectData()

maybe this can give you some ideas.

The way how I would write it:

DataTable ret = new DataTable();
ret.Columns.Add("Orders", typeof(int));
ret.Columns.Add("Date", typeof(string));
ret.Columns.Add("Country", typeof(string));

ret.Rows.Add(10, DateTime.Parse("7-8-2015").Date.ToString(), "DE");
return ret;

/Dmitrij

 
Andrey Kozachuk
Reply

Thank you for the link. I tried your approach of rows creating - the same error.

If table needs to be saved somewhere, question is where to save it.

 
Andrey Kozachuk
Reply

The problem was in ColorColunm property - it is a required field to override. I overrided it and added Color column to DataTable. Now everything works

 

You must be logged in to post in the forum