Oops Posted April 4, 2007 Report Share Posted April 4, 2007 Im going bonkers... im trying to create a simple datatable and attach it to a chart as a datasource.But when i run the program, the compiler throws a system.formatexception and shows the message "Input string was not in a correct format". I have visual studio 2005 and .net 2.0, i have managed to get other datasets (which were poulated by queries to database) connected to the chart and get them to run properly, but only when i MANUALLY try to populate a datable with data and then connect to the chart, do i get this error..... this must be a big silly one...but i cant get it right now... heres the code //Create Data Table at runtimeDataTable dtTemp = new DataTable();dtTemp.Columns.Add("Dates");dtTemp.Columns.Add("Percentages"); //Add one rowDataRow dr1 = dtTemp.NewRow();DateTime dt1 = new DateTime(2007, 02, 01);dr1["Dates"] = dt1.Date ;dr1["Percentages"] = 50;dtTemp.Rows.Add(dr1);dtTemp.AcceptChanges(); //Add another rowDataRow dr2 = dtTemp.NewRow();DateTime dt2 = new DateTime(2007, 02, 02);dr2["Dates"] = dt2.Date ;dr2["Percentages"] = 100;dtTemp.Rows.Add(dr2);dtTemp.AcceptChanges(); Chart1.DataSourceSettings.Fields.Add(new FieldMap("Dates",FieldUsage.XValue));Chart1.DataSourceSettings.Fields.Add(new FieldMap("Percentages", FieldUsage.Value));Chart1.DataSource = ds1 ; Chart1.DataBind(); Link to comment Share on other sites More sharing options...
JuanC Posted April 5, 2007 Report Share Posted April 5, 2007 When binding against datatable or datasources, we query the datatable for information about the type of the columns instead of discovering it from the data (we do try to discover when reading data from text files). This means you have to change the way you create the datatable columns as follows dtTemp.Columns.Add("Dates",typeof(DateTime));dtTemp.Columns.Add("Percentages",typeof(double));"Dates",typeof(DateTime));dtTemp.Columns.Add("Percentages",typeof(double));Regards, JuanC Link to comment Share on other sites More sharing options...
Oops Posted April 5, 2007 Author Report Share Posted April 5, 2007 Very many thanks. You are a life saver and i need to read up more on data controls . Thanks again. Link to comment Share on other sites More sharing options...
Frank Posted April 12, 2007 Report Share Posted April 12, 2007 FYI. When trying to convert a string to data Chart FX will always assume the string is a number. In your case, one of the strings was a date. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.