Strange issue with .mrt file (int to int - type casting issue)
Posted: Wed Jan 08, 2020 8:43 am
Hello,
I got stuck up with a strange issue with Stimulsoft PDF rendering process.
Issue Details:-
I have a database table "Products" with column "Product_Id" and its datatype is integer.
In the .mrt file, there is a text box control (Text1) located inside the DataBand control. In the Text1_BeforePrint event contains the following code
Strange Issue
During the PDF rendering process with asp.net web application, it throws a type casting exception "Cannot implicitly convert type 'string' to 'int'" in the very first line of code.
int Product_ID= Products.Product_Id;
I am wondering why it throws error when the column ProductId is already int column.
No issue with XML DataSource
We have checked the same .mrt file with XML datasource but this time it rendered the PDF perfectly without issue.
Version Details
.Net Version :- Asp.net 4.0
Stimulsoft Version :- 2018.1.6
Note
Here, i intend is to know why the above issue occurred when the data passed via asp.net application Dataset but not with XML datasource.
As of now, we have overcome this issue by using the type casting int.Parse() as below,
To reproduce the same issue at your end, Kindly use the attached .mrt file and the below code with .net application
To check the same with xml kindly use the attached data.xml and data.xsd files.
I got stuck up with a strange issue with Stimulsoft PDF rendering process.
Issue Details:-
I have a database table "Products" with column "Product_Id" and its datatype is integer.
In the .mrt file, there is a text box control (Text1) located inside the DataBand control. In the Text1_BeforePrint event contains the following code
Code: Select all
int Product_ID= Products.Product_Id; //It throws an error
//int Product_ID=int.Parse(Products.Product_Id.ToString()); This would revolve the issue
if(Product_ID>123)
{
Text1.TextValue="If loop";
}
else
{
Text1.TextValue="Else Loop";
}
During the PDF rendering process with asp.net web application, it throws a type casting exception "Cannot implicitly convert type 'string' to 'int'" in the very first line of code.
int Product_ID= Products.Product_Id;
I am wondering why it throws error when the column ProductId is already int column.
No issue with XML DataSource
We have checked the same .mrt file with XML datasource but this time it rendered the PDF perfectly without issue.
Version Details
.Net Version :- Asp.net 4.0
Stimulsoft Version :- 2018.1.6
Note
Here, i intend is to know why the above issue occurred when the data passed via asp.net application Dataset but not with XML datasource.
As of now, we have overcome this issue by using the type casting int.Parse() as below,
Code: Select all
int Product_ID=int.Parse(Products.Product_Id);
To reproduce the same issue at your end, Kindly use the attached .mrt file and the below code with .net application
Code: Select all
protected void btn_GeneratePDF_Click(object sender, EventArgs e)
{
DataSet ds_Source = GetSource();
//ExportXML(ds_Source);
GeneratePDF(templatePath, ds_Source);
}
public void GeneratePDF(string templatePath,DataSet ds_InputData)
{
Report.Load(templatePath);
Report.Dictionary.Databases.Clear();
Report.Dictionary.DataSources.Clear();
Report.RegData(ds_InputData);
Report.Dictionary.Synchronize();
Report.Compile();
Report.Render(true);
using (Stream ostream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"CurrentPDFs\Sample.PDF", FileMode.OpenOrCreate, FileAccess.Write))
{
Report.ExportDocument(StiExportFormat.Pdf, ostream);
}
}
public class Employee
{
public string Employee_Name { get; set; }
public int Employee_ID { get; set; }
}
public class Products
{
public string Product_Name { get; set; }
public int Product_Id { get; set; }
}
public DataSet GetSource()
{
/**/
List<Employee> Students = new List<Employee>(){
new Employee() { Employee_Name = "Pradeep", Employee_ID = 100 },
new Employee() { Employee_Name = "Smith", Employee_ID = 101},
new Employee() { Employee_Name = "John", Employee_ID = 102 }
};
List<Products> ProductInformation = new List<Products>(){
new Products() { Product_Name = "Chrysler", Product_Id = 123},
new Products() { Product_Name = "Donnellys", Product_Id = 456},
};
DataSet ds_ExtensionMethod = new DataSet();
ExtensionMethod extensionMethod = new ExtensionMethod();
ds_ExtensionMethod.Tables.Add(extensionMethod.ToDataTable(Students));
ds_ExtensionMethod.Tables.Add(extensionMethod.ToDataTable(ProductInformation));
return ds_ExtensionMethod;
}
To check the same with xml kindly use the attached data.xml and data.xsd files.